git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #303 from garyb/auto-prelude
7d378e0Phil Freeman
examples/manual/passing/Import.purs+3
@@ -1,5 +1,7 @@
1module M1 where
1module M1 where
2
2
3+ import Prelude ()
4+
3 id :: forall a. a -> a
5 id :: forall a. a -> a
4 id = \x -> x
6 id = \x -> x
5
7
@@ -7,6 +9,7 @@ module M1 where
7
9
8module M2 where
10module M2 where
9
11
12+ import Prelude ()
10 import M1
13 import M1
11
14
12 main = \_ -> foo 42
15 main = \_ -> foo 42
examples/manual/passing/RedefinedFixity.purs+6
@@ -1,15 +1,21 @@
1module M1 where
1module M1 where
2
2
3+import Prelude ()
4+
3($) f a = f a
5($) f a = f a
4
6
5infixr 1000 $
7infixr 1000 $
6
8
7module M2 where
9module M2 where
8
10
11+import Prelude ()
12+
9import M1
13import M1
10
14
11module M3 where
15module M3 where
12
16
17+import Prelude ()
18+
13import M1
19import M1
14import M2
20import M2
15
21
examples/passing/Applicative.purs+2
@@ -1,5 +1,7 @@
1module Main where
1module Main where
2
2
3+import Prelude ()
4+
3class Applicative f where
5class Applicative f where
4 pure :: forall a. a -> f a
6 pure :: forall a. a -> f a
5 (<*>) :: forall a b. f (a -> b) -> f a -> f b
7 (<*>) :: forall a b. f (a -> b) -> f a -> f b
examples/passing/ArrayType.purs+1
@@ -1,5 +1,6 @@
1module Main where
1module Main where
2
2
3+import Prelude ()
3import Data.Array
4import Data.Array
4
5
5test :: [] Number
6test :: [] Number
examples/passing/AutoPrelude.pursnew file+8
@@ -0,0 +1,8 @@
1+module Main where
2+
3+import Debug.Trace
4+
5+f x = x * 10
6+g y = y - 10
7+
8+main = trace $ show $ (f <<< g) 100
examples/passing/AutoPrelude2.pursnew file+9
@@ -0,0 +1,9 @@
1+module Main where
2+
3+import qualified Prelude as P
4+import Debug.Trace
5+
6+f :: forall a. a -> a
7+f = P.id
8+
9+main = P.($) trace ((f P.<<< f) "Done")
examples/passing/Church.purs+2
@@ -1,5 +1,7 @@
1module Main where
1module Main where
2
2
3+ import Prelude ()
4+
3 type List a = forall r. r -> (a -> r -> r) -> r
5 type List a = forall r. r -> (a -> r -> r) -> r
4
6
5 empty :: forall a. List a
7 empty :: forall a. List a
examples/passing/Conditional.purs+2
@@ -1,5 +1,7 @@
1module Main where
1module Main where
2
2
3+ import Prelude ()
4+
3 fns = \f -> if f true then f else \x -> x
5 fns = \f -> if f true then f else \x -> x
4
6
5 not = \x -> if x then false else true
7 not = \x -> if x then false else true
examples/passing/Dollar.purs+2
@@ -1,5 +1,7 @@
1module Main where
1module Main where
2
2
3+import Prelude ()
4+
3($) :: forall a b. (a -> b) -> a -> b
5($) :: forall a b. (a -> b) -> a -> b
4($) f x = f x
6($) f x = f x
5
7
examples/passing/Monad.purs+2
@@ -1,5 +1,7 @@
1module Main where
1module Main where
2
2
3+ import Prelude ()
4+
3 type Monad m = { return :: forall a. a -> m a
5 type Monad m = { return :: forall a. a -> m a
4 , bind :: forall a b. m a -> (a -> m b) -> m b }
6 , bind :: forall a b. m a -> (a -> m b) -> m b }
5
7
src/Language/PureScript/Sugar/Names.hs+17−3
@@ -134,9 +134,10 @@ addExport exports name =
134--
134--
135desugarImports :: [Module] -> Either String [Module]
135desugarImports :: [Module] -> Either String [Module]
136desugarImports modules = do
136desugarImports modules = do
137+ let modules' = importPrelude `map` modules
137− unfilteredExports <- findExports modules
138+ unfilteredExports <- findExports modules'
138− exports <- foldM filterModuleExports unfilteredExports modules
139+ exports <- foldM filterModuleExports unfilteredExports modules'
139− mapM (renameInModule' unfilteredExports exports) modules
140+ mapM (renameInModule' unfilteredExports exports) modules'
140 where
141 where
141
142
142 -- Filters the exports for a module in the global exports environment so that only explicitly
143 -- Filters the exports for a module in the global exports environment so that only explicitly
@@ -155,6 +156,19 @@ desugarImports modules = do
155 imports <- resolveImports env m
156 imports <- resolveImports env m
156 renameInModule imports env (elaborateExports exps m)
157 renameInModule imports env (elaborateExports exps m)
157
158
159+-- |
160+-- Add an import declaration for the Prelude to a module if it does not already explicitly import
161+-- it.
162+--
163+importPrelude :: Module -> Module
164+importPrelude m@(Module mn decls exps) =
165+ if isPreludeImport `any` decls then m
166+ else Module mn (preludeImport : decls) exps
167+ where
168+ isPreludeImport (ImportDeclaration (ModuleName [ProperName "Prelude"]) _ _) = True
169+ isPreludeImport _ = False
170+ preludeImport = ImportDeclaration (ModuleName [ProperName "Prelude"]) Nothing Nothing
171+
158-- |
172-- |
159-- Rethrow an error with the name of the current module in the case of a failure
173-- Rethrow an error with the name of the current module in the case of a failure
160--
174--