git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix some bugs, fix remaining passing examples, still need to fix prelude.
d2d684cPhil Freeman
examples/shelltest/Foreach.js+1−1
@@ -1 +1 @@
1−console.log(sum([1,2,3,4,5]));
1+console.log(Foreach.sum([1,2,3,4,5]));
examples/shelltest/List.js+4−4
@@ -1,7 +1,7 @@
1−var l1 = Cons({ head: 1, tail: Nil });
1+var l1 = List.Cons({ head: 1, tail: List.Nil });
2−var l2 = Cons({ head: 2, tail: Nil });
2+var l2 = List.Cons({ head: 2, tail: List.Nil });
3−var l3 = Cons({ head: l1, tail: Cons({ head: l2, tail: Nil }) });
3+var l3 = List.Cons({ head: l1, tail: List.Cons({ head: l2, tail: List.Nil }) });
4−var flat = flatten(l3);
4+var flat = List.flatten(l3);
5var f1 = flat.value.head;
5var f1 = flat.value.head;
6var f2 = flat.value.tail.value.head
6var f2 = flat.value.tail.value.head
7console.log([f1, f2]);
7console.log([f1, f2]);
examples/shelltest/Maybe.js+3−3
@@ -1,5 +1,5 @@
1−console.log(bind(Just("a"))(function(a) {
1+console.log(Maybe.bind(Maybe.Just("a"))(function(a) {
2− return bind(Just("b"))(function(b) {
2+ return Maybe.bind(Maybe.Just("b"))(function(b) {
3− return Just(a + b);
3+ return Maybe.Just(a + b);
4 });
4 });
5}));
5}));
examples/shelltest/runAll.test+1−1
@@ -2,7 +2,7 @@
2mkdir -p tests && ../../dist/build/psc/psc ../passing/Maybe.purs -o tests/Maybe.js && cat tests/Maybe.js Maybe.js | nodejs
2mkdir -p tests && ../../dist/build/psc/psc ../passing/Maybe.purs -o tests/Maybe.js && cat tests/Maybe.js Maybe.js | nodejs
3<<<
3<<<
4>>>
4>>>
5−{ ctor: 'Just', value: 'ab' }
5+{ ctor: 'Maybe.Just', value: 'ab' }
6>>>2
6>>>2
7>>>= 0
7>>>= 0
8
8
libraries/prelude/prelude.purs+15−11
@@ -15,7 +15,7 @@ module Prelude where
15 (<|) :: forall a b c. (b -> c) -> (a -> b) -> a -> c
15 (<|) :: forall a b c. (b -> c) -> (a -> b) -> a -> c
16 (<|) = flip (|>)
16 (<|) = flip (|>)
17
17
18− -- Maybe
18+module Maybe where
19
19
20 data Maybe a = Nothing | Just a
20 data Maybe a = Nothing | Just a
21
21
@@ -24,12 +24,12 @@ module Prelude where
24 maybe _ f (Just a) = f a
24 maybe _ f (Just a) = f a
25
25
26 fromMaybe :: forall a. a -> Maybe a -> a
26 fromMaybe :: forall a. a -> Maybe a -> a
27− fromMaybe a = maybe a id
27+ fromMaybe a = maybe a Prelude.id
28
28
29 bindMaybe :: forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
29 bindMaybe :: forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
30 bindMaybe m f = maybe Nothing f m
30 bindMaybe m f = maybe Nothing f m
31
31
32− -- Either
32+module Either where
33
33
34 data Either a b = Left a | Right b
34 data Either a b = Left a | Right b
35
35
@@ -40,7 +40,9 @@ module Prelude where
40 bindEither :: forall e a b. Either e a -> (a -> Either e b) -> Either e b
40 bindEither :: forall e a b. Either e a -> (a -> Either e b) -> Either e b
41 bindEither = either (\e _ -> Left e) (\a f -> f a)
41 bindEither = either (\e _ -> Left e) (\a f -> f a)
42
42
43− -- Arrays
43+module Arrays where
44+
45+ import Maybe
44
46
45 head :: forall a. [a] -> a
47 head :: forall a. [a] -> a
46 head (x : _) = x
48 head (x : _) = x
@@ -96,7 +98,7 @@ module Prelude where
96 foreign import splice :: forall a. Number -> Number -> [a] -> [a] -> [a]
98 foreign import splice :: forall a. Number -> Number -> [a] -> [a] -> [a]
97
99
98 cons :: forall a. a -> [a] -> [a]
100 cons :: forall a. a -> [a] -> [a]
99− cons = \a -> concat([a])
101+ cons a = concat [a]
100
102
101 concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
103 concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
102 concatMap as f = {
104 concatMap as f = {
@@ -146,7 +148,9 @@ module Prelude where
146 return true;
148 return true;
147 }
149 }
148
150
149− -- Pairs
151+module Tuple where
152+
153+ import Arrays
150
154
151 type Tuple a b = { fst :: a, snd :: b }
155 type Tuple a b = { fst :: a, snd :: b }
152
156
@@ -157,7 +161,7 @@ module Prelude where
157 uncurry f t = f t.fst t.snd
161 uncurry f t = f t.fst t.snd
158
162
159 tuple :: forall a b. a -> b -> Tuple a b
163 tuple :: forall a b. a -> b -> Tuple a b
160− tuple = curry id
164+ tuple = curry Prelude.id
161
165
162 zip :: forall a b. [a] -> [b] -> [Tuple a b]
166 zip :: forall a b. [a] -> [b] -> [Tuple a b]
163 zip = zipWith tuple
167 zip = zipWith tuple
@@ -167,7 +171,7 @@ module Prelude where
167 { fst = as, snd = bs } -> tuple (cons t.fst as) (cons t.snd bs)
171 { fst = as, snd = bs } -> tuple (cons t.fst as) (cons t.snd bs)
168 unzip [] = tuple [] []
172 unzip [] = tuple [] []
169
173
170− -- Strings
174+module String where
171
175
172 foreign import member "length" lengthS :: String -> Number
176 foreign import member "length" lengthS :: String -> Number
173
177
@@ -195,7 +199,7 @@ module Prelude where
195
199
196 foreign import trim :: String -> String
200 foreign import trim :: String -> String
197
201
198− -- Regex
202+module Regex where
199
203
200 foreign import data Regex :: *
204 foreign import data Regex :: *
201
205
@@ -209,7 +213,7 @@ module Prelude where
209
213
210 foreign import search :: Regex -> String -> Number
214 foreign import search :: Regex -> String -> Number
211
215
212− -- Globals
216+module Global where
213
217
214 foreign import nan :: Number
218 foreign import nan :: Number
215
219
@@ -239,7 +243,7 @@ module Prelude where
239
243
240 foreign import decodeURI :: String -> String
244 foreign import decodeURI :: String -> String
241
245
242− -- Math
246+module Math where
243
247
244 type Math =
248 type Math =
245 { abs :: Number -> Number
249 { abs :: Number -> Number
src/Language/PureScript/Operators.hs+7−7
@@ -37,7 +37,7 @@ rebracket :: [Module] -> Either String [Module]
37rebracket ms = forM ms $ \(Module name ds) -> do
37rebracket ms = forM ms $ \(Module name ds) -> do
38 m <- collectFixities (ModuleName name) ds
38 m <- collectFixities (ModuleName name) ds
39 let opTable = customOperatorTable m
39 let opTable = customOperatorTable m
40− ds' <- G.everywhereM' (G.mkM (matchOperators opTable)) ds
40+ ds' <- G.everywhereM' (G.mkM (matchOperators (ModuleName name) opTable)) ds
41 return $ Module name $ G.everywhere (G.mkT removeParens) ds'
41 return $ Module name $ G.everywhere (G.mkT removeParens) ds'
42
42
43removeParens :: Value -> Value
43removeParens :: Value -> Value
@@ -56,8 +56,8 @@ customOperatorTable fixities =
56
56
57type Chain = [Either Value (Qualified Ident)]
57type Chain = [Either Value (Qualified Ident)]
58
58
59−matchOperators :: [[(Qualified Ident, Value -> Value -> Value, Associativity)]] -> Value -> Either String Value
59+matchOperators :: ModuleName -> [[(Qualified Ident, Value -> Value -> Value, Associativity)]] -> Value -> Either String Value
60−matchOperators ops val = G.everywhereM' (G.mkM parseChains) val
60+matchOperators moduleName ops val = G.everywhereM' (G.mkM parseChains) val
61 where
61 where
62 parseChains :: Value -> Either String Value
62 parseChains :: Value -> Either String Value
63 parseChains b@(BinaryNoParens _ _ _) = bracketChain (extendChain b)
63 parseChains b@(BinaryNoParens _ _ _) = bracketChain (extendChain b)
@@ -67,7 +67,7 @@ matchOperators ops val = G.everywhereM' (G.mkM parseChains) val
67 extendChain other = [Left other]
67 extendChain other = [Left other]
68 bracketChain :: Chain -> Either String Value
68 bracketChain :: Chain -> Either String Value
69 bracketChain = either (Left . show) Right . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
69 bracketChain = either (Left . show) Right . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
70− opTable = map (map (\(name, f, a) -> P.Infix (P.try (matchOp name) >> return f) (toAssoc a))) ops
70+ opTable = map (map (\(name, f, a) -> P.Infix (P.try (matchOp moduleName name) >> return f) (toAssoc a))) ops
71 ++ [[P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) [t1]) [t2]))) P.AssocLeft]]
71 ++ [[P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) [t1]) [t2]))) P.AssocLeft]]
72
72
73toAssoc :: Associativity -> P.Assoc
73toAssoc :: Associativity -> P.Assoc
@@ -80,10 +80,10 @@ parseValue = P.token show (const (P.initialPos "")) (either Just (const Nothing)
80parseOp :: P.Parsec Chain () (Qualified Ident)
80parseOp :: P.Parsec Chain () (Qualified Ident)
81parseOp = P.token show (const (P.initialPos "")) (either (const Nothing) Just) P.<?> "operator"
81parseOp = P.token show (const (P.initialPos "")) (either (const Nothing) Just) P.<?> "operator"
82
82
83−matchOp :: Qualified Ident -> P.Parsec Chain () ()
83+matchOp :: ModuleName -> Qualified Ident -> P.Parsec Chain () ()
84−matchOp op = do
84+matchOp moduleName op = do
85 ident <- parseOp
85 ident <- parseOp
86− guard (ident == op)
86+ guard (qualify moduleName ident == qualify moduleName op)
87
87
88collectFixities :: ModuleName -> [Declaration] -> Either String (M.Map (Qualified Ident) Fixity)
88collectFixities :: ModuleName -> [Declaration] -> Either String (M.Map (Qualified Ident) Fixity)
89collectFixities = go M.empty
89collectFixities = go M.empty
src/Language/PureScript/TypeChecker/Synonyms.hs+8−8
@@ -27,22 +27,22 @@ import Data.Generics.Extras
27import Control.Monad.Writer
27import Control.Monad.Writer
28import Control.Monad.Error
28import Control.Monad.Error
29
29
30−buildTypeSubstitution :: Qualified ProperName -> Int -> Type -> Either String (Maybe Type)
30+buildTypeSubstitution :: ModuleName -> Qualified ProperName -> Int -> Type -> Either String (Maybe Type)
31−buildTypeSubstitution name n = go n []
31+buildTypeSubstitution moduleName name n = go n []
32 where
32 where
33 go :: Int -> [Type] -> Type -> Either String (Maybe Type)
33 go :: Int -> [Type] -> Type -> Either String (Maybe Type)
34− go 0 args (TypeConstructor ctor) | name == ctor = return (Just $ SaturatedTypeSynonym ctor args)
34+ go 0 args (TypeConstructor ctor) | qualify moduleName name == qualify moduleName ctor = return (Just $ SaturatedTypeSynonym ctor args)
35 go m _ (TypeConstructor ctor) | m > 0 && name == ctor = throwError $ "Partially applied type synonym " ++ show name
35 go m _ (TypeConstructor ctor) | m > 0 && name == ctor = throwError $ "Partially applied type synonym " ++ show name
36 go m args (TypeApp f arg) = go (m - 1) (arg:args) f
36 go m args (TypeApp f arg) = go (m - 1) (arg:args) f
37 go _ _ _ = return Nothing
37 go _ _ _ = return Nothing
38
38
39−saturateTypeSynonym :: (Data d) => Qualified ProperName -> Int -> d -> Either String d
39+saturateTypeSynonym :: (Data d) => ModuleName -> Qualified ProperName -> Int -> d -> Either String d
40−saturateTypeSynonym name n = everywhereM' (mkM replace)
40+saturateTypeSynonym moduleName name n = everywhereM' (mkM replace)
41 where
41 where
42− replace t = fmap (fromMaybe t) $ buildTypeSubstitution name n t
42+ replace t = fmap (fromMaybe t) $ buildTypeSubstitution moduleName name n t
43
43
44−saturateAllTypeSynonyms :: (Data d) => [(Qualified ProperName, Int)] -> d -> Either String d
44+saturateAllTypeSynonyms :: (Data d) => ModuleName -> [(Qualified ProperName, Int)] -> d -> Either String d
45−saturateAllTypeSynonyms syns d = foldM (\result (name, n) -> saturateTypeSynonym name n result) d syns
45+saturateAllTypeSynonyms moduleName syns d = foldM (\result (name, n) -> saturateTypeSynonym moduleName name n result) d syns
46
46
47
47
48
48
src/Language/PureScript/TypeChecker/Types.hs+3−2
@@ -238,11 +238,12 @@ replaceVarWithUnknown ident ty = do
238 ru <- fresh
238 ru <- fresh
239 return $ replaceRowVars ident ru . replaceTypeVars ident tu $ ty
239 return $ replaceRowVars ident ru . replaceTypeVars ident tu $ ty
240
240
241−replaceAllTypeSynonyms :: (Functor m, MonadState CheckState m, MonadError String m) => (D.Data d) => d -> m d
241+replaceAllTypeSynonyms :: (Functor m, MonadState CheckState m, MonadReader SubstContext m, MonadError String m) => (D.Data d) => d -> m d
242replaceAllTypeSynonyms d = do
242replaceAllTypeSynonyms d = do
243 env <- getEnv
243 env <- getEnv
244+ moduleName <- substCurrentModule <$> ask
244 let syns = map (\((path, name), (args, _)) -> (Qualified (Just path) name, length args)) . M.toList $ typeSynonyms env
245 let syns = map (\((path, name), (args, _)) -> (Qualified (Just path) name, length args)) . M.toList $ typeSynonyms env
245− either throwError return $ saturateAllTypeSynonyms syns d
246+ either throwError return $ saturateAllTypeSynonyms moduleName syns d
246
247
247desaturateAllTypeSynonyms :: (D.Data d) => d -> d
248desaturateAllTypeSynonyms :: (D.Data d) => d -> d
248desaturateAllTypeSynonyms = everywhere (mkT replaceSaturatedTypeSynonym)
249desaturateAllTypeSynonyms = everywhere (mkT replaceSaturatedTypeSynonym)