git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #483 from purescript/implicit-prim
22900aaPhil Freeman
examples/passing/EmptyDataDecls.purs+6−6
@@ -5,10 +5,10 @@ import Prelude
5data Z
5data Z
6data S n
6data S n
7
7
8−data Array n a = Array [a]
8+data ArrayBox n a = ArrayBox [a]
9
9
10−nil :: forall a. Array Z a
10+nil :: forall a. ArrayBox Z a
11−nil = Array []
11+nil = ArrayBox []
12
12
13foreign import concat
13foreign import concat
14 "function concat(l1) {\
14 "function concat(l1) {\
@@ -17,8 +17,8 @@ foreign import concat
17 \ };\
17 \ };\
18 \}" :: forall a. [a] -> [a] -> [a]
18 \}" :: forall a. [a] -> [a] -> [a]
19
19
20−cons' :: forall a n. a -> Array n a -> Array (S n) a
20+cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
21−cons' x (Array xs) = Array $ concat [x] xs
21+cons' x (ArrayBox xs) = ArrayBox $ concat [x] xs
22
22
23foreign import error
23foreign import error
24 "function error(msg) {\
24 "function error(msg) {\
@@ -26,5 +26,5 @@ foreign import error
26 \}" :: forall a. String -> a
26 \}" :: forall a. String -> a
27
27
28main = case cons' 1 $ cons' 2 $ cons' 3 nil of
28main = case cons' 1 $ cons' 2 $ cons' 3 nil of
29− Array [1, 2, 3] -> Debug.Trace.trace "Done"
29+ ArrayBox [1, 2, 3] -> Debug.Trace.trace "Done"
30 _ -> error "Failed"
30 _ -> error "Failed"
src/Language/PureScript.hs+16−13
@@ -70,7 +70,7 @@ compile = compile' initEnvironment
70
70
71compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
71compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
72compile' env opts ms = do
72compile' env opts ms = do
73− (sorted, _) <- sortModules $ if optionsNoPrelude opts then ms else (map importPrelude ms)
73+ (sorted, _) <- sortModules $ map importPrim $ if optionsNoPrelude opts then ms else (map importPrelude ms)
74 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
74 (desugared, nextVar) <- stringifyErrorStack True $ runSupplyT 0 $ desugar sorted
75 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
75 (elaborated, env') <- runCheck' opts env $ forM desugared $ typeCheckModule mainModuleIdent
76 regrouped <- stringifyErrorStack True $ createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
76 regrouped <- stringifyErrorStack True $ createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
@@ -170,7 +170,7 @@ make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options
170make outputDir opts ms = do
170make outputDir opts ms = do
171 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
171 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
172
172
173− (sorted, graph) <- liftError $ sortModules $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
173+ (sorted, graph) <- liftError $ sortModules $ map importPrim $ if optionsNoPrelude opts then map snd ms else (map (importPrelude . snd) ms)
174
174
175 toRebuild <- foldM (\s (Module moduleName' _ _) -> do
175 toRebuild <- foldM (\s (Module moduleName' _ _) -> do
176 let filePath = runModuleName moduleName'
176 let filePath = runModuleName moduleName'
@@ -241,16 +241,19 @@ reverseDependencies g = combine [ (dep, mn) | (mn, deps) <- g, dep <- deps ]
241 combine = M.fromList . map ((fst . head) &&& map snd) . groupBy ((==) `on` fst) . sortBy (compare `on` fst)
241 combine = M.fromList . map ((fst . head) &&& map snd) . groupBy ((==) `on` fst) . sortBy (compare `on` fst)
242
242
243-- |
243-- |
244−-- Add an import declaration for the Prelude to a module if it does not already explicitly import
244+-- Add an import declaration for a module if it does not already explicitly import it.
245−-- it.
246--
245--
247−importPrelude :: Module -> Module
246+addDefaultImport :: ModuleName -> Module -> Module
248−importPrelude m@(Module mn decls exps) =
247+addDefaultImport toImport m@(Module mn decls exps) =
249− if isPreludeImport `any` decls || mn == prelude then m
248+ if isExistingImport `any` decls || mn == toImport then m
250− else Module mn (preludeImport : decls) exps
249+ else Module mn (ImportDeclaration toImport Nothing Nothing : decls) exps
251 where
250 where
252− prelude = ModuleName [ProperName C.prelude]
253− isPreludeImport (ImportDeclaration (ModuleName [ProperName mn']) _ _) | mn' == C.prelude = True
251+ isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
254− isPreludeImport (PositionedDeclaration _ d) = isPreludeImport d
252+ isExistingImport (PositionedDeclaration _ d) = isExistingImport d
255− isPreludeImport _ = False
253+ isExistingImport _ = False
256− preludeImport = ImportDeclaration prelude Nothing Nothing
254+
255+importPrim :: Module -> Module
256+importPrim = addDefaultImport (ModuleName [ProperName C.prim])
257+
258+importPrelude :: Module -> Module
259+importPrelude = addDefaultImport (ModuleName [ProperName C.prelude])
src/Language/PureScript/Environment.hs+1−1
@@ -1,6 +1,6 @@
1-----------------------------------------------------------------------------
1-----------------------------------------------------------------------------
2--
2--
3−-- Module : Language.PureScript.Prim
3+-- Module : Language.PureScript.Environment
4-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
4-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5-- License : MIT
5-- License : MIT
6--
6--
src/Language/PureScript/Parser/Types.hs+1−13
@@ -30,15 +30,6 @@ import Language.PureScript.Environment
30import qualified Text.Parsec as P
30import qualified Text.Parsec as P
31import qualified Text.Parsec.Expr as P
31import qualified Text.Parsec.Expr as P
32
32
33−parseNumber :: P.Parsec String ParseState Type
34−parseNumber = const tyNumber <$> reserved "Number"
35−
36−parseString :: P.Parsec String ParseState Type
37−parseString = const tyString <$> reserved "String"
38−
39−parseBoolean :: P.Parsec String ParseState Type
40−parseBoolean = const tyBoolean <$> reserved "Boolean"
41−
42parseArray :: P.Parsec String ParseState Type
33parseArray :: P.Parsec String ParseState Type
43parseArray = squares $ return tyArray
34parseArray = squares $ return tyArray
44
35
@@ -69,10 +60,7 @@ parseForAll = mkForAll <$> (P.try (reserved "forall") *> P.many1 (indented *> id
69--
60--
70parseTypeAtom :: P.Parsec String ParseState Type
61parseTypeAtom :: P.Parsec String ParseState Type
71parseTypeAtom = indented *> P.choice (map P.try
62parseTypeAtom = indented *> P.choice (map P.try
72− [ parseNumber
73− , parseString
74− , parseBoolean
75− , parseArray
63+ [ parseArray
76 , parseArrayOf
64 , parseArrayOf
77 , parseFunction
65 , parseFunction
78 , parseObject
66 , parseObject
src/Language/PureScript/Sugar/Names.hs+3−1
@@ -31,6 +31,8 @@ import Language.PureScript.Environment
31import Language.PureScript.Errors
31import Language.PureScript.Errors
32import Language.PureScript.Traversals
32import Language.PureScript.Traversals
33
33
34+import qualified Language.PureScript.Constants as C
35+
34-- |
36-- |
35-- The global export environment - every declaration exported from every module.
37-- The global export environment - every declaration exported from every module.
36--
38--
@@ -272,7 +274,7 @@ renameInModule imports exports (Module mn decls exps) =
272-- Finds all exported declarations in a set of modules.
274-- Finds all exported declarations in a set of modules.
273--
275--
274findExports :: [Module] -> Either ErrorStack ExportEnvironment
276findExports :: [Module] -> Either ErrorStack ExportEnvironment
275−findExports = foldM addModule $ M.singleton (ModuleName [ProperName "Prim"]) primExports
277+findExports = foldM addModule $ M.singleton (ModuleName [ProperName C.prim]) primExports
276 where
278 where
277
279
278 -- The exported types from the Prim module
280 -- The exported types from the Prim module