git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
A start on #253
2e0c57dPhil Freeman
docs/source/prelude.rst+56−56
@@ -18,7 +18,7 @@ Type Classes
18
18
19 class Applicative f where
19 class Applicative f where
20 pure :: forall a. a -> f a
20 pure :: forall a. a -> f a
21− (<*>) :: forall b. forall a. f (a -> b) -> f a -> f b
21+ (<*>) :: forall a b. f (a -> b) -> f a -> f b
22
22
23 class Bits b where
23 class Bits b where
24 (&) :: b -> b -> b
24 (&) :: b -> b -> b
@@ -36,19 +36,19 @@ Type Classes
36
36
37 class Category a where
37 class Category a where
38 id :: forall t. a t t
38 id :: forall t. a t t
39− (<<<) :: forall d. forall c. forall b. a c d -> a b c -> a b d
39+ (<<<) :: forall b c d. a c d -> a b c -> a b d
40− (>>>) :: forall d. forall c. forall b. a b c -> a c d -> a b d
40+ (>>>) :: forall b c d. a b c -> a c d -> a b d
41
41
42 class Eq a where
42 class Eq a where
43 (==) :: a -> a -> Prim.Boolean
43 (==) :: a -> a -> Prim.Boolean
44 (/=) :: a -> a -> Prim.Boolean
44 (/=) :: a -> a -> Prim.Boolean
45
45
46 class Functor f where
46 class Functor f where
47− (<$>) :: forall b. forall a. (a -> b) -> f a -> f b
47+ (<$>) :: forall a b. (a -> b) -> f a -> f b
48
48
49 class Monad m where
49 class Monad m where
50 return :: forall a. a -> m a
50 return :: forall a. a -> m a
51− (>>=) :: forall b. forall a. m a -> (a -> m b) -> m b
51+ (>>=) :: forall a b. m a -> (a -> m b) -> m b
52
52
53 class Num a where
53 class Num a where
54 (+) :: a -> a -> a
54 (+) :: a -> a -> a
@@ -116,9 +116,9 @@ Values
116
116
117 (!!) :: forall a. [a] -> Prim.Number -> a
117 (!!) :: forall a. [a] -> Prim.Number -> a
118
118
119− (#) :: forall b. forall a. a -> (a -> b) -> b
119+ (#) :: forall a b. a -> (a -> b) -> b
120
120
121− ($) :: forall b. forall a. (a -> b) -> a -> b
121+ ($) :: forall a b. (a -> b) -> a -> b
122
122
123 (++) :: Prim.String -> Prim.String -> Prim.String
123 (++) :: Prim.String -> Prim.String -> Prim.String
124
124
@@ -128,9 +128,9 @@ Values
128
128
129 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
129 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
130
130
131− const :: forall b. forall a. a -> b -> a
131+ const :: forall a b. a -> b -> a
132
132
133− flip :: forall c. forall b. forall a. (a -> b -> c) -> b -> a -> c
133+ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
134
134
135 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
135 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
136
136
@@ -203,7 +203,7 @@ Values
203
203
204::
204::
205
205
206− mconcat :: forall m. (Monoid (m)) => [m] -> m
206+ mconcat :: forall m. (Monoid m) => [m] -> m
207
207
208Module Control.Monad
208Module Control.Monad
209--------------------
209--------------------
@@ -222,23 +222,23 @@ Values
222
222
223::
223::
224
224
225− (<=<) :: forall c. forall b. forall a. forall m. (Monad (m)) => (b -> m c) -> (a -> m b) -> a -> m c
225+ (<=<) :: forall m a b c. (Monad m) => (b -> m c) -> (a -> m b) -> a -> m c
226
226
227− (>=>) :: forall c. forall b. forall a. forall m. (Monad (m)) => (a -> m b) -> (b -> m c) -> a -> m c
227+ (>=>) :: forall m a b c. (Monad m) => (a -> m b) -> (b -> m c) -> a -> m c
228
228
229− foldM :: forall b. forall a. forall m. (Monad (m)) => (a -> b -> m a) -> a -> [b] -> m a
229+ foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
230
230
231− join :: forall a. forall m. (Monad (m)) => m (m a) -> m a
231+ join :: forall m a. (Monad m) => m (m a) -> m a
232
232
233− mapM :: forall b. forall a. forall m. (Monad (m)) => (a -> m b) -> [a] -> m [b]
233+ mapM :: forall m a b. (Monad m) => (a -> m b) -> [a] -> m [b]
234
234
235− replicateM :: forall a. forall m. (Monad (m)) => Prim.Number -> m a -> m [a]
235+ replicateM :: forall m a. (Monad m) => Prim.Number -> m a -> m [a]
236
236
237− sequence :: forall a. forall m. (Monad (m)) => [m a] -> m [a]
237+ sequence :: forall m a. (Monad m) => [m a] -> m [a]
238
238
239− when :: forall m. (Monad (m)) => Prim.Boolean -> m { } -> m { }
239+ when :: forall m. (Monad m) => Prim.Boolean -> m { } -> m { }
240
240
241− zipWithM :: forall c. forall b. forall a. forall m. (Monad (m)) => (a -> b -> m c) -> [a] -> [b] -> m [c]
241+ zipWithM :: forall m a b c. (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
242
242
243Module Data.Maybe
243Module Data.Maybe
244-----------------
244-----------------
@@ -275,7 +275,7 @@ Values
275
275
276 fromMaybe :: forall a. a -> Maybe a -> a
276 fromMaybe :: forall a. a -> Maybe a -> a
277
277
278− maybe :: forall b. forall a. b -> (a -> b) -> Maybe a -> b
278+ maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
279
279
280Module Data.Either
280Module Data.Either
281------------------
281------------------
@@ -310,7 +310,7 @@ Values
310
310
311::
311::
312
312
313− either :: forall c. forall b. forall a. (a -> c) -> (b -> c) -> Either a b -> c
313+ either :: forall a b c. (a -> c) -> (b -> c) -> Either a b -> c
314
314
315Module Data.Array
315Module Data.Array
316-----------------
316-----------------
@@ -347,7 +347,7 @@ Values
347
347
348 concat :: forall a. [a] -> [a] -> [a]
348 concat :: forall a. [a] -> [a] -> [a]
349
349
350− concatMap :: forall b. forall a. [a] -> (a -> [b]) -> [b]
350+ concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
351
351
352 deleteAt :: forall a. Prim.Number -> Prim.Number -> [a] -> [a]
352 deleteAt :: forall a. Prim.Number -> Prim.Number -> [a] -> [a]
353
353
@@ -357,9 +357,9 @@ Values
357
357
358 find :: forall a. (a -> Prim.Boolean) -> [a] -> Maybe a
358 find :: forall a. (a -> Prim.Boolean) -> [a] -> Maybe a
359
359
360− foldl :: forall b. forall a. (b -> a -> b) -> b -> [a] -> b
360+ foldl :: forall a b. (b -> a -> b) -> b -> [a] -> b
361
361
362− foldr :: forall b. forall a. (a -> b -> a) -> a -> [b] -> a
362+ foldr :: forall a b. (a -> b -> a) -> a -> [b] -> a
363
363
364 head :: forall a. [a] -> Maybe a
364 head :: forall a. [a] -> Maybe a
365
365
@@ -377,7 +377,7 @@ Values
377
377
378 length :: forall a. [a] -> Prim.Number
378 length :: forall a. [a] -> Prim.Number
379
379
380− map :: forall b. forall a. (a -> b) -> [a] -> [b]
380+ map :: forall a b. (a -> b) -> [a] -> [b]
381
381
382 push :: forall a. [a] -> a -> [a]
382 push :: forall a. [a] -> a -> [a]
383
383
@@ -399,7 +399,7 @@ Values
399
399
400 updateAt :: forall a. Prim.Number -> a -> [a] -> [a]
400 updateAt :: forall a. Prim.Number -> a -> [a] -> [a]
401
401
402− zipWith :: forall c. forall b. forall a. (a -> b -> c) -> [a] -> [b] -> [c]
402+ zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
403
403
404Module Data.Eq
404Module Data.Eq
405--------------
405--------------
@@ -427,7 +427,7 @@ Values
427
427
428::
428::
429
429
430− liftRef :: forall b. forall a. (a -> a -> b) -> Ref a -> Ref a -> b
430+ liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
431
431
432 refEq :: forall a. Ref a -> Ref a -> Prim.Boolean
432 refEq :: forall a. Ref a -> Ref a -> Prim.Boolean
433
433
@@ -480,13 +480,13 @@ Values
480
480
481::
481::
482
482
483− curry :: forall c. forall b. forall a. (Tuple a b -> c) -> a -> b -> c
483+ curry :: forall a b c. (Tuple a b -> c) -> a -> b -> c
484
484
485− uncurry :: forall c. forall b. forall a. (a -> b -> c) -> Tuple a b -> c
485+ uncurry :: forall a b c. (a -> b -> c) -> Tuple a b -> c
486
486
487− unzip :: forall b. forall a. [Tuple a b] -> Tuple [a] [b]
487+ unzip :: forall a b. [Tuple a b] -> Tuple [a] [b]
488
488
489− zip :: forall b. forall a. [a] -> [b] -> [Tuple a b]
489+ zip :: forall a b. [a] -> [b] -> [Tuple a b]
490
490
491Module Data.String
491Module Data.String
492------------------
492------------------
@@ -652,13 +652,13 @@ Values
652
652
653 log2e :: Prim.Number
653 log2e :: Prim.Number
654
654
655− max :: Prim.Number -> Prim.Number
655+ max :: Prim.Number -> Prim.Number -> Prim.Number
656
656
657− min :: Prim.Number -> Prim.Number
657+ min :: Prim.Number -> Prim.Number -> Prim.Number
658
658
659 pi :: Prim.Number
659 pi :: Prim.Number
660
660
661− pow :: Prim.Number -> Prim.Number
661+ pow :: Prim.Number -> Prim.Number -> Prim.Number
662
662
663 round :: Prim.Number -> Prim.Number
663 round :: Prim.Number -> Prim.Number
664
664
@@ -699,19 +699,19 @@ Values
699
699
700::
700::
701
701
702− bindEff :: forall b. forall a. forall e. Eff e a -> (a -> Eff e b) -> Eff e b
702+ bindEff :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
703
703
704 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
704 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
705
705
706− foreachE :: forall a. forall e. [a] -> (a -> Eff e { }) -> Eff e { }
706+ foreachE :: forall e a. [a] -> (a -> Eff e { }) -> Eff e { }
707
707
708− retEff :: forall a. forall e. a -> Eff e a
708+ retEff :: forall e a. a -> Eff e a
709
709
710 runPure :: forall a. Pure a -> a
710 runPure :: forall a. Pure a -> a
711
711
712 untilE :: forall e. Eff e Prim.Boolean -> Eff e { }
712 untilE :: forall e. Eff e Prim.Boolean -> Eff e { }
713
713
714− whileE :: forall a. forall e. Eff e Prim.Boolean -> Eff e a -> Eff e { }
714+ whileE :: forall e a. Eff e Prim.Boolean -> Eff e a -> Eff e { }
715
715
716Module Control.Monad.Eff.Unsafe
716Module Control.Monad.Eff.Unsafe
717-------------------------------
717-------------------------------
@@ -730,7 +730,7 @@ Values
730
730
731::
731::
732
732
733− unsafeInterleaveEff :: forall a. forall eff2. forall eff1. Eff eff1 a -> Eff eff2 a
733+ unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
734
734
735Module Random
735Module Random
736-------------
736-------------
@@ -776,9 +776,9 @@ Values
776
776
777::
777::
778
778
779− catchError :: forall a. forall r. forall e. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
779+ catchError :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
780
780
781− throwError :: forall r. forall e. forall a. e -> Eff (err :: Error e | r) a
781+ throwError :: forall a e r. e -> Eff (err :: Error e | r) a
782
782
783Module Data.IORef
783Module Data.IORef
784-----------------
784-----------------
@@ -803,15 +803,15 @@ Values
803
803
804::
804::
805
805
806− modifyIORef :: forall r. forall s. IORef s -> (s -> s) -> Eff (ref :: Ref | r) { }
806+ modifyIORef :: forall s r. IORef s -> (s -> s) -> Eff (ref :: Ref | r) { }
807
807
808− newIORef :: forall r. forall s. s -> Eff (ref :: Ref | r) (IORef s)
808+ newIORef :: forall s r. s -> Eff (ref :: Ref | r) (IORef s)
809
809
810− readIORef :: forall r. forall s. IORef s -> Eff (ref :: Ref | r) s
810+ readIORef :: forall s r. IORef s -> Eff (ref :: Ref | r) s
811
811
812− unsafeRunIORef :: forall a. forall eff. Eff (ref :: Ref | eff) a -> Eff eff a
812+ unsafeRunIORef :: forall eff a. Eff (ref :: Ref | eff) a -> Eff eff a
813
813
814− writeIORef :: forall r. forall s. IORef s -> s -> Eff (ref :: Ref | r) { }
814+ writeIORef :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) { }
815
815
816Module Debug.Trace
816Module Debug.Trace
817------------------
817------------------
@@ -834,7 +834,7 @@ Values
834
834
835::
835::
836
836
837− print :: forall r. forall a. (Show (a)) => a -> Eff (trace :: Trace | r) { }
837+ print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) { }
838
838
839 trace :: forall r. Prim.String -> Eff (trace :: Trace | r) { }
839 trace :: forall r. Prim.String -> Eff (trace :: Trace | r) { }
840
840
@@ -863,23 +863,23 @@ Values
863
863
864::
864::
865
865
866− modifySTRef :: forall r. forall h. forall a. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
866+ modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
867
867
868− newSTArray :: forall r. forall h. forall a. Prim.Number -> a -> Eff (st :: ST h | r) (STArray h a)
868+ newSTArray :: forall a h r. Prim.Number -> a -> Eff (st :: ST h | r) (STArray h a)
869
869
870− newSTRef :: forall r. forall h. forall a. a -> Eff (st :: ST h | r) (STRef h a)
870+ newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
871
871
872− peekSTArray :: forall r. forall h. forall a. STArray h a -> Eff (st :: ST h | r) a
872+ peekSTArray :: forall a h r. STArray h a -> Eff (st :: ST h | r) a
873
873
874− pokeSTArray :: forall r. forall h. forall a. STArray h a -> Prim.Number -> a -> Eff (st :: ST h | r) a
874+ pokeSTArray :: forall a h r. STArray h a -> Prim.Number -> a -> Eff (st :: ST h | r) a
875
875
876− readSTRef :: forall r. forall h. forall a. STRef h a -> Eff (st :: ST h | r) a
876+ readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
877
877
878− runST :: forall r. forall a. forall h. Eff (st :: ST h | r) a -> Eff r a
878+ runST :: forall a r. forall h. Eff (st :: ST h | r) a -> Eff r a
879
879
880− runSTArray :: forall r. forall a. forall h. Eff (st :: ST h | r) (STArray h a) -> Eff r [a]
880+ runSTArray :: forall a r. forall h. Eff (st :: ST h | r) (STArray h a) -> Eff r [a]
881
881
882− writeSTRef :: forall r. forall h. forall a. STRef h a -> a -> Eff (st :: ST h | r) a
882+ writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
883
883
884Module Data.Enum
884Module Data.Enum
885----------------
885----------------
prelude/README.md+56−56
@@ -12,7 +12,7 @@
12
12
13 class Applicative f where
13 class Applicative f where
14 pure :: forall a. a -> f a
14 pure :: forall a. a -> f a
15− (<*>) :: forall b. forall a. f (a -> b) -> f a -> f b
15+ (<*>) :: forall a b. f (a -> b) -> f a -> f b
16
16
17 class Bits b where
17 class Bits b where
18 (&) :: b -> b -> b
18 (&) :: b -> b -> b
@@ -30,19 +30,19 @@
30
30
31 class Category a where
31 class Category a where
32 id :: forall t. a t t
32 id :: forall t. a t t
33− (<<<) :: forall d. forall c. forall b. a c d -> a b c -> a b d
33+ (<<<) :: forall b c d. a c d -> a b c -> a b d
34− (>>>) :: forall d. forall c. forall b. a b c -> a c d -> a b d
34+ (>>>) :: forall b c d. a b c -> a c d -> a b d
35
35
36 class Eq a where
36 class Eq a where
37 (==) :: a -> a -> Prim.Boolean
37 (==) :: a -> a -> Prim.Boolean
38 (/=) :: a -> a -> Prim.Boolean
38 (/=) :: a -> a -> Prim.Boolean
39
39
40 class Functor f where
40 class Functor f where
41− (<$>) :: forall b. forall a. (a -> b) -> f a -> f b
41+ (<$>) :: forall a b. (a -> b) -> f a -> f b
42
42
43 class Monad m where
43 class Monad m where
44 return :: forall a. a -> m a
44 return :: forall a. a -> m a
45− (>>=) :: forall b. forall a. m a -> (a -> m b) -> m b
45+ (>>=) :: forall a b. m a -> (a -> m b) -> m b
46
46
47 class Num a where
47 class Num a where
48 (+) :: a -> a -> a
48 (+) :: a -> a -> a
@@ -106,9 +106,9 @@
106
106
107 (!!) :: forall a. [a] -> Prim.Number -> a
107 (!!) :: forall a. [a] -> Prim.Number -> a
108
108
109− (#) :: forall b. forall a. a -> (a -> b) -> b
109+ (#) :: forall a b. a -> (a -> b) -> b
110
110
111− ($) :: forall b. forall a. (a -> b) -> a -> b
111+ ($) :: forall a b. (a -> b) -> a -> b
112
112
113 (++) :: Prim.String -> Prim.String -> Prim.String
113 (++) :: Prim.String -> Prim.String -> Prim.String
114
114
@@ -118,9 +118,9 @@
118
118
119 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
119 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
120
120
121− const :: forall b. forall a. a -> b -> a
121+ const :: forall a b. a -> b -> a
122
122
123− flip :: forall c. forall b. forall a. (a -> b -> c) -> b -> a -> c
123+ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
124
124
125 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
125 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
126
126
@@ -186,7 +186,7 @@
186
186
187### Values
187### Values
188
188
189− mconcat :: forall m. (Monoid (m)) => [m] -> m
189+ mconcat :: forall m. (Monoid m) => [m] -> m
190
190
191
191
192## Module Control.Monad
192## Module Control.Monad
@@ -202,23 +202,23 @@
202
202
203### Values
203### Values
204
204
205− (<=<) :: forall c. forall b. forall a. forall m. (Monad (m)) => (b -> m c) -> (a -> m b) -> a -> m c
205+ (<=<) :: forall m a b c. (Monad m) => (b -> m c) -> (a -> m b) -> a -> m c
206
206
207− (>=>) :: forall c. forall b. forall a. forall m. (Monad (m)) => (a -> m b) -> (b -> m c) -> a -> m c
207+ (>=>) :: forall m a b c. (Monad m) => (a -> m b) -> (b -> m c) -> a -> m c
208
208
209− foldM :: forall b. forall a. forall m. (Monad (m)) => (a -> b -> m a) -> a -> [b] -> m a
209+ foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
210
210
211− join :: forall a. forall m. (Monad (m)) => m (m a) -> m a
211+ join :: forall m a. (Monad m) => m (m a) -> m a
212
212
213− mapM :: forall b. forall a. forall m. (Monad (m)) => (a -> m b) -> [a] -> m [b]
213+ mapM :: forall m a b. (Monad m) => (a -> m b) -> [a] -> m [b]
214
214
215− replicateM :: forall a. forall m. (Monad (m)) => Prim.Number -> m a -> m [a]
215+ replicateM :: forall m a. (Monad m) => Prim.Number -> m a -> m [a]
216
216
217− sequence :: forall a. forall m. (Monad (m)) => [m a] -> m [a]
217+ sequence :: forall m a. (Monad m) => [m a] -> m [a]
218
218
219− when :: forall m. (Monad (m)) => Prim.Boolean -> m { } -> m { }
219+ when :: forall m. (Monad m) => Prim.Boolean -> m { } -> m { }
220
220
221− zipWithM :: forall c. forall b. forall a. forall m. (Monad (m)) => (a -> b -> m c) -> [a] -> [b] -> m [c]
221+ zipWithM :: forall m a b c. (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
222
222
223
223
224## Module Data.Maybe
224## Module Data.Maybe
@@ -248,7 +248,7 @@
248
248
249 fromMaybe :: forall a. a -> Maybe a -> a
249 fromMaybe :: forall a. a -> Maybe a -> a
250
250
251− maybe :: forall b. forall a. b -> (a -> b) -> Maybe a -> b
251+ maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
252
252
253
253
254## Module Data.Either
254## Module Data.Either
@@ -276,7 +276,7 @@
276
276
277### Values
277### Values
278
278
279− either :: forall c. forall b. forall a. (a -> c) -> (b -> c) -> Either a b -> c
279+ either :: forall a b c. (a -> c) -> (b -> c) -> Either a b -> c
280
280
281
281
282## Module Data.Array
282## Module Data.Array
@@ -308,7 +308,7 @@
308
308
309 concat :: forall a. [a] -> [a] -> [a]
309 concat :: forall a. [a] -> [a] -> [a]
310
310
311− concatMap :: forall b. forall a. [a] -> (a -> [b]) -> [b]
311+ concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
312
312
313 deleteAt :: forall a. Prim.Number -> Prim.Number -> [a] -> [a]
313 deleteAt :: forall a. Prim.Number -> Prim.Number -> [a] -> [a]
314
314
@@ -318,9 +318,9 @@
318
318
319 find :: forall a. (a -> Prim.Boolean) -> [a] -> Maybe a
319 find :: forall a. (a -> Prim.Boolean) -> [a] -> Maybe a
320
320
321− foldl :: forall b. forall a. (b -> a -> b) -> b -> [a] -> b
321+ foldl :: forall a b. (b -> a -> b) -> b -> [a] -> b
322
322
323− foldr :: forall b. forall a. (a -> b -> a) -> a -> [b] -> a
323+ foldr :: forall a b. (a -> b -> a) -> a -> [b] -> a
324
324
325 head :: forall a. [a] -> Maybe a
325 head :: forall a. [a] -> Maybe a
326
326
@@ -338,7 +338,7 @@
338
338
339 length :: forall a. [a] -> Prim.Number
339 length :: forall a. [a] -> Prim.Number
340
340
341− map :: forall b. forall a. (a -> b) -> [a] -> [b]
341+ map :: forall a b. (a -> b) -> [a] -> [b]
342
342
343 push :: forall a. [a] -> a -> [a]
343 push :: forall a. [a] -> a -> [a]
344
344
@@ -360,7 +360,7 @@
360
360
361 updateAt :: forall a. Prim.Number -> a -> [a] -> [a]
361 updateAt :: forall a. Prim.Number -> a -> [a] -> [a]
362
362
363− zipWith :: forall c. forall b. forall a. (a -> b -> c) -> [a] -> [b] -> [c]
363+ zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
364
364
365
365
366## Module Data.Eq
366## Module Data.Eq
@@ -381,7 +381,7 @@
381
381
382### Values
382### Values
383
383
384− liftRef :: forall b. forall a. (a -> a -> b) -> Ref a -> Ref a -> b
384+ liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
385
385
386 refEq :: forall a. Ref a -> Ref a -> Prim.Boolean
386 refEq :: forall a. Ref a -> Ref a -> Prim.Boolean
387
387
@@ -424,13 +424,13 @@
424
424
425### Values
425### Values
426
426
427− curry :: forall c. forall b. forall a. (Tuple a b -> c) -> a -> b -> c
427+ curry :: forall a b c. (Tuple a b -> c) -> a -> b -> c
428
428
429− uncurry :: forall c. forall b. forall a. (a -> b -> c) -> Tuple a b -> c
429+ uncurry :: forall a b c. (a -> b -> c) -> Tuple a b -> c
430
430
431− unzip :: forall b. forall a. [Tuple a b] -> Tuple [a] [b]
431+ unzip :: forall a b. [Tuple a b] -> Tuple [a] [b]
432
432
433− zip :: forall b. forall a. [a] -> [b] -> [Tuple a b]
433+ zip :: forall a b. [a] -> [b] -> [Tuple a b]
434
434
435
435
436## Module Data.String
436## Module Data.String
@@ -582,13 +582,13 @@
582
582
583 log2e :: Prim.Number
583 log2e :: Prim.Number
584
584
585− max :: Prim.Number -> Prim.Number
585+ max :: Prim.Number -> Prim.Number -> Prim.Number
586
586
587− min :: Prim.Number -> Prim.Number
587+ min :: Prim.Number -> Prim.Number -> Prim.Number
588
588
589 pi :: Prim.Number
589 pi :: Prim.Number
590
590
591− pow :: Prim.Number -> Prim.Number
591+ pow :: Prim.Number -> Prim.Number -> Prim.Number
592
592
593 round :: Prim.Number -> Prim.Number
593 round :: Prim.Number -> Prim.Number
594
594
@@ -622,19 +622,19 @@
622
622
623### Values
623### Values
624
624
625− bindEff :: forall b. forall a. forall e. Eff e a -> (a -> Eff e b) -> Eff e b
625+ bindEff :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
626
626
627 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
627 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
628
628
629− foreachE :: forall a. forall e. [a] -> (a -> Eff e { }) -> Eff e { }
629+ foreachE :: forall e a. [a] -> (a -> Eff e { }) -> Eff e { }
630
630
631− retEff :: forall a. forall e. a -> Eff e a
631+ retEff :: forall e a. a -> Eff e a
632
632
633 runPure :: forall a. Pure a -> a
633 runPure :: forall a. Pure a -> a
634
634
635 untilE :: forall e. Eff e Prim.Boolean -> Eff e { }
635 untilE :: forall e. Eff e Prim.Boolean -> Eff e { }
636
636
637− whileE :: forall a. forall e. Eff e Prim.Boolean -> Eff e a -> Eff e { }
637+ whileE :: forall e a. Eff e Prim.Boolean -> Eff e a -> Eff e { }
638
638
639
639
640## Module Control.Monad.Eff.Unsafe
640## Module Control.Monad.Eff.Unsafe
@@ -650,7 +650,7 @@
650
650
651### Values
651### Values
652
652
653− unsafeInterleaveEff :: forall a. forall eff2. forall eff1. Eff eff1 a -> Eff eff2 a
653+ unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
654
654
655
655
656## Module Random
656## Module Random
@@ -686,9 +686,9 @@
686
686
687### Values
687### Values
688
688
689− catchError :: forall a. forall r. forall e. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
689+ catchError :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
690
690
691− throwError :: forall r. forall e. forall a. e -> Eff (err :: Error e | r) a
691+ throwError :: forall a e r. e -> Eff (err :: Error e | r) a
692
692
693
693
694## Module Data.IORef
694## Module Data.IORef
@@ -708,15 +708,15 @@
708
708
709### Values
709### Values
710
710
711− modifyIORef :: forall r. forall s. IORef s -> (s -> s) -> Eff (ref :: Ref | r) { }
711+ modifyIORef :: forall s r. IORef s -> (s -> s) -> Eff (ref :: Ref | r) { }
712
712
713− newIORef :: forall r. forall s. s -> Eff (ref :: Ref | r) (IORef s)
713+ newIORef :: forall s r. s -> Eff (ref :: Ref | r) (IORef s)
714
714
715− readIORef :: forall r. forall s. IORef s -> Eff (ref :: Ref | r) s
715+ readIORef :: forall s r. IORef s -> Eff (ref :: Ref | r) s
716
716
717− unsafeRunIORef :: forall a. forall eff. Eff (ref :: Ref | eff) a -> Eff eff a
717+ unsafeRunIORef :: forall eff a. Eff (ref :: Ref | eff) a -> Eff eff a
718
718
719− writeIORef :: forall r. forall s. IORef s -> s -> Eff (ref :: Ref | r) { }
719+ writeIORef :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) { }
720
720
721
721
722## Module Debug.Trace
722## Module Debug.Trace
@@ -734,7 +734,7 @@
734
734
735### Values
735### Values
736
736
737− print :: forall r. forall a. (Show (a)) => a -> Eff (trace :: Trace | r) { }
737+ print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) { }
738
738
739 trace :: forall r. Prim.String -> Eff (trace :: Trace | r) { }
739 trace :: forall r. Prim.String -> Eff (trace :: Trace | r) { }
740
740
@@ -758,23 +758,23 @@
758
758
759### Values
759### Values
760
760
761− modifySTRef :: forall r. forall h. forall a. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
761+ modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
762
762
763− newSTArray :: forall r. forall h. forall a. Prim.Number -> a -> Eff (st :: ST h | r) (STArray h a)
763+ newSTArray :: forall a h r. Prim.Number -> a -> Eff (st :: ST h | r) (STArray h a)
764
764
765− newSTRef :: forall r. forall h. forall a. a -> Eff (st :: ST h | r) (STRef h a)
765+ newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
766
766
767− peekSTArray :: forall r. forall h. forall a. STArray h a -> Eff (st :: ST h | r) a
767+ peekSTArray :: forall a h r. STArray h a -> Eff (st :: ST h | r) a
768
768
769− pokeSTArray :: forall r. forall h. forall a. STArray h a -> Prim.Number -> a -> Eff (st :: ST h | r) a
769+ pokeSTArray :: forall a h r. STArray h a -> Prim.Number -> a -> Eff (st :: ST h | r) a
770
770
771− readSTRef :: forall r. forall h. forall a. STRef h a -> Eff (st :: ST h | r) a
771+ readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
772
772
773− runST :: forall r. forall a. forall h. Eff (st :: ST h | r) a -> Eff r a
773+ runST :: forall a r. forall h. Eff (st :: ST h | r) a -> Eff r a
774
774
775− runSTArray :: forall r. forall a. forall h. Eff (st :: ST h | r) (STArray h a) -> Eff r [a]
775+ runSTArray :: forall a r. forall h. Eff (st :: ST h | r) (STArray h a) -> Eff r [a]
776
776
777− writeSTRef :: forall r. forall h. forall a. STRef h a -> a -> Eff (st :: ST h | r) a
777+ writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
778
778
779
779
780## Module Data.Enum
780## Module Data.Enum
psci/Main.hs+4−4
@@ -173,8 +173,8 @@ completion = completeWord Nothing " \t\n\r" findCompletions
173 let matches = filter (isPrefixOf str) (names ms)
173 let matches = filter (isPrefixOf str) (names ms)
174 return $ sortBy sorter $ map simpleCompletion matches ++ files
174 return $ sortBy sorter $ map simpleCompletion matches ++ files
175 getDeclName :: Maybe [P.DeclarationRef] -> P.Declaration -> Maybe P.Ident
175 getDeclName :: Maybe [P.DeclarationRef] -> P.Declaration -> Maybe P.Ident
176− getDeclName Nothing (P.ValueDeclaration ident _ _ _) = Just ident
176+ getDeclName Nothing (P.ValueDeclaration ident _ _ _ _) = Just ident
177− getDeclName (Just exts) (P.ValueDeclaration ident _ _ _) | isExported = Just ident
177+ getDeclName (Just exts) (P.ValueDeclaration ident _ _ _ _) | isExported = Just ident
178 where
178 where
179 isExported = flip any exts $ \e -> case e of
179 isExported = flip any exts $ \e -> case e of
180 P.ValueRef ident' -> ident == ident'
180 P.ValueRef ident' -> ident == ident'
@@ -209,8 +209,8 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
209 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
209 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
210 itValue = foldl (\x f -> f x) value lets
210 itValue = foldl (\x f -> f x) value lets
211 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
211 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
212− itDecl = P.ValueDeclaration (P.Ident "it") [] Nothing itValue
212+ itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] Nothing itValue
213− mainDecl = P.ValueDeclaration (P.Ident "main") [] Nothing mainValue
213+ mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] Nothing mainValue
214 decls = if exec then [itDecl, mainDecl] else [itDecl]
214 decls = if exec then [itDecl, mainDecl] else [itDecl]
215 in
215 in
216 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
216 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
src/Language/PureScript/CodeGen/Externs.hs+42−23
@@ -17,36 +17,55 @@ module Language.PureScript.CodeGen.Externs (
17 moduleToPs
17 moduleToPs
18) where
18) where
19
19
20−import Data.Maybe (maybeToList, mapMaybe)
20+import Data.List (intercalate)
21+
21import qualified Data.Map as M
22import qualified Data.Map as M
23+
24+import Control.Monad.Writer
25+
22import Language.PureScript.Declarations
26import Language.PureScript.Declarations
23import Language.PureScript.TypeChecker.Monad
27import Language.PureScript.TypeChecker.Monad
24import Language.PureScript.Pretty
28import Language.PureScript.Pretty
25import Language.PureScript.Names
29import Language.PureScript.Names
26−import Data.List (intercalate)
30+import Language.PureScript.Types
31+import Language.PureScript.Kinds
27
32
28-- |
33-- |
29-- Generate foreign imports for all declarations in a module
34-- Generate foreign imports for all declarations in a module
30−-- TODO: only expose items listed in "exps"
31--
35--
32moduleToPs :: Module -> Environment -> String
36moduleToPs :: Module -> Environment -> String
33−moduleToPs (Module mn decls _) env =
37+moduleToPs (Module moduleName _ exts) env = intercalate "\n" . execWriter $ do
34− "module " ++ runModuleName mn ++ " where\n" ++
38+ tell ["module " ++ runModuleName moduleName ++ " where"]
35− (intercalate "\n" . map (" " ++) . concatMap (declToPs mn env) $ decls)
39+ let typesExported = getTypesExportedFrom moduleName exts env
36−
40+ forM_ typesExported $ \(pn, kind) ->
37−declToPs :: ModuleName -> Environment -> Declaration -> [String]
41+ tell ["foreign import data " ++ show pn ++ " :: " ++ prettyPrintKind kind]
38−declToPs path env (ValueDeclaration name _ _ _) = maybeToList $ do
42+ let namesExported = getNamesExportedFrom moduleName exts env
39− (ty, _) <- M.lookup (path, name) $ names env
43+ forM_ namesExported $ \(ident, ty) ->
40− return $ "foreign import " ++ show name ++ " :: " ++ prettyPrintType ty
44+ tell ["foreign import " ++ show ident ++ " :: " ++ prettyPrintType ty]
41−declToPs path env (BindingGroupDeclaration vals) =
45+
42− flip mapMaybe vals $ \(name, _) -> do
46+getNamesExportedFrom :: ModuleName -> Maybe [DeclarationRef] -> Environment -> [(Ident, Type)]
43− (ty, _) <- M.lookup (path, name) $ names env
47+getNamesExportedFrom moduleName exps env =
44− return $ "foreign import " ++ show name ++ " :: " ++ prettyPrintType ty
48+ [ (ident, ty)
45−declToPs path env (DataDeclaration name _ _) = maybeToList $ do
49+ | ((moduleName', ident), (ty, nameKind)) <- M.toList . names $ env
50+ , moduleName == moduleName'
51+ , nameKind `elem` [Value, Extern ForeignImport]
52+ , isExported ident exps
53+ ]
54+ where
55+ isExported :: Ident -> Maybe [DeclarationRef] -> Bool
56+ isExported _ Nothing = True
57+ isExported ident (Just exps') = ValueRef ident `elem` exps'
58+
59+getTypesExportedFrom :: ModuleName -> Maybe [DeclarationRef] -> Environment -> [(ProperName, Kind)]
60+getTypesExportedFrom moduleName exps env =
61+ [ (pn, kind)
46− kind <- M.lookup (Qualified (Just path) name) $ types env
62+ | ((Qualified (Just moduleName') pn), kind) <- M.toList . types $ env
47− return $ "foreign import data " ++ show name ++ " :: " ++ prettyPrintKind kind
63+ , moduleName == moduleName'
48−declToPs _ _ (ExternDataDeclaration name kind) =
64+ , isExported pn exps
49− return $ "foreign import data " ++ show name ++ " :: " ++ prettyPrintKind kind
65+ ]
50−declToPs _ _ (TypeSynonymDeclaration name args ty) =
66+ where
51− return $ "type " ++ show name ++ " " ++ unwords args ++ " = " ++ prettyPrintType ty
67+ isExported :: ProperName -> Maybe [DeclarationRef] -> Bool
52−declToPs _ _ _ = []
68+ isExported _ Nothing = True
69+ isExported pn (Just exps') = flip any exps' $ \e -> case e of
70+ TypeRef pn' _ | pn == pn' -> True
71+ _ -> False
src/Language/PureScript/CodeGen/JS.hs+10−13
@@ -30,7 +30,7 @@ import Control.Monad (replicateM, forM)
30
30
31import qualified Data.Map as M
31import qualified Data.Map as M
32
32
33−import Language.PureScript.TypeChecker (Environment(..), NameKind(..))
33+import Language.PureScript.TypeChecker (Environment(..))
34import Language.PureScript.Values
34import Language.PureScript.Values
35import Language.PureScript.Names
35import Language.PureScript.Names
36import Language.PureScript.Scope
36import Language.PureScript.Scope
@@ -62,10 +62,10 @@ moduleToJs opts (Module name decls _) env =
62-- Generate code in the simplified Javascript intermediate representation for a declaration
62-- Generate code in the simplified Javascript intermediate representation for a declaration
63--
63--
64declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
64declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
65−declToJs opts mp (ValueDeclaration ident _ _ val) e =
65+declToJs opts mp (ValueDeclaration ident _ _ _ val) e =
66 Just $ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
66 Just $ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
67declToJs opts mp (BindingGroupDeclaration vals) e =
67declToJs opts mp (BindingGroupDeclaration vals) e =
68− Just $ concatMap (\(ident, val) ->
68+ Just $ concatMap (\(ident, _, val) ->
69 export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
69 export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
70 ) vals
70 ) vals
71declToJs _ mp (DataDeclaration _ _ ctors) _ =
71declToJs _ mp (DataDeclaration _ _ ctors) _ =
@@ -231,7 +231,7 @@ binderToJs _ _ varName done (VarBinder ident) =
231 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : done)
231 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : done)
232binderToJs m e varName done (ConstructorBinder ctor bs) = do
232binderToJs m e varName done (ConstructorBinder ctor bs) = do
233 js <- go 0 done bs
233 js <- go 0 done bs
234− if isOnlyConstructor m e ctor
234+ if isOnlyConstructor e ctor
235 then
235 then
236 return js
236 return js
237 else
237 else
@@ -284,17 +284,14 @@ binderToJs m e varName done (NamedBinder ident binder) = do
284-- Checks whether a data constructor is the only constructor for that type, used to simplify the
284-- Checks whether a data constructor is the only constructor for that type, used to simplify the
285-- check when generating code for binders.
285-- check when generating code for binders.
286--
286--
287−isOnlyConstructor :: ModuleName -> Environment -> Qualified ProperName -> Bool
287+isOnlyConstructor :: Environment -> Qualified ProperName -> Bool
288−isOnlyConstructor m e ctor =
288+isOnlyConstructor e ctor =
289 let ty = fromMaybe (error "Data constructor not found") $ ctor `M.lookup` dataConstructors e
289 let ty = fromMaybe (error "Data constructor not found") $ ctor `M.lookup` dataConstructors e
290− in numConstructors ty == 1
290+ in numConstructors (ctor, ty) == 1
291 where
291 where
292− numConstructors ty = length $ filter (((==) `on` typeConstructor) ty) $ M.elems $ dataConstructors e
292+ numConstructors ty = length $ filter (((==) `on` typeConstructor) ty) $ M.toList $ dataConstructors e
293− typeConstructor (TypeConstructor qual) = qualify m qual
293+ typeConstructor (Qualified (Just moduleName) _, (tyCtor, _)) = (moduleName, tyCtor)
294− typeConstructor (ForAll _ ty _) = typeConstructor ty
295− typeConstructor (TypeApp (TypeApp t _) ty) | t == tyFunction = typeConstructor ty
296− typeConstructor (TypeApp ty _) = typeConstructor ty
297− typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn
294+ typeConstructor _ = error "Invalid argument to isOnlyConstructor"
298
295
299wrapExportsContainer :: Options -> [JS] -> JS
296wrapExportsContainer :: Options -> [JS] -> JS
300wrapExportsContainer opts modules = JSApp (JSFunction Nothing [C._ps] $ JSBlock $ JSStringLiteral "use strict" : modules) [exportSelector]
297wrapExportsContainer opts modules = JSApp (JSFunction Nothing [C._ps] $ JSBlock $ JSStringLiteral "use strict" : modules) [exportSelector]
src/Language/PureScript/DeadCodeElimination.hs+5−5
@@ -42,10 +42,10 @@ declarationsByModule :: Module -> [(Key, [Key])]
42declarationsByModule (Module moduleName ds _) = concatMap go ds
42declarationsByModule (Module moduleName ds _) = concatMap go ds
43 where
43 where
44 go :: Declaration -> [(Key, [Key])]
44 go :: Declaration -> [(Key, [Key])]
45− go d@(ValueDeclaration name _ _ _) = [((moduleName, Left name), dependencies moduleName d)]
45+ go d@(ValueDeclaration name _ _ _ _) = [((moduleName, Left name), dependencies moduleName d)]
46 go (DataDeclaration _ _ dctors) = map (\(name, _) -> ((moduleName, Right name), [])) dctors
46 go (DataDeclaration _ _ dctors) = map (\(name, _) -> ((moduleName, Right name), [])) dctors
47 go (ExternDeclaration _ name _ _) = [((moduleName, Left name), [])]
47 go (ExternDeclaration _ name _ _) = [((moduleName, Left name), [])]
48− go d@(BindingGroupDeclaration names') = map (\(name, _) -> ((moduleName, Left name), dependencies moduleName d)) names'
48+ go d@(BindingGroupDeclaration names') = map (\(name, _, _) -> ((moduleName, Left name), dependencies moduleName d)) names'
49 go (DataBindingGroupDeclaration ds') = concatMap go ds'
49 go (DataBindingGroupDeclaration ds') = concatMap go ds'
50 go _ = []
50 go _ = []
51
51
@@ -59,7 +59,7 @@ dependencies moduleName = nub . everything (++) (mkQ [] values)
59 values _ = []
59 values _ = []
60
60
61isUsed :: ModuleName -> Graph -> (Key -> Maybe Vertex) -> [Vertex] -> Declaration -> Bool
61isUsed :: ModuleName -> Graph -> (Key -> Maybe Vertex) -> [Vertex] -> Declaration -> Bool
62−isUsed moduleName graph vertexFor entryPointVertices (ValueDeclaration name _ _ _) =
62+isUsed moduleName graph vertexFor entryPointVertices (ValueDeclaration name _ _ _ _) =
63 let Just v' = vertexFor (moduleName, Left name)
63 let Just v' = vertexFor (moduleName, Left name)
64 in any (\v -> path graph v v') entryPointVertices
64 in any (\v -> path graph v v') entryPointVertices
65isUsed moduleName graph vertexFor entryPointVertices (DataDeclaration _ _ dctors) =
65isUsed moduleName graph vertexFor entryPointVertices (DataDeclaration _ _ dctors) =
@@ -69,8 +69,8 @@ isUsed moduleName graph vertexFor entryPointVertices (ExternDeclaration _ name _
69 let Just v' = vertexFor (moduleName, Left name)
69 let Just v' = vertexFor (moduleName, Left name)
70 in any (\v -> path graph v v') entryPointVertices
70 in any (\v -> path graph v v') entryPointVertices
71isUsed moduleName graph vertexFor entryPointVertices (BindingGroupDeclaration ds) =
71isUsed moduleName graph vertexFor entryPointVertices (BindingGroupDeclaration ds) =
72− any (\(name, _) -> let Just v' = vertexFor (moduleName, Left name)
72+ any (\(name, _, _) -> let Just v' = vertexFor (moduleName, Left name)
73− in any (\v -> path graph v v') entryPointVertices) ds
73+ in any (\v -> path graph v v') entryPointVertices) ds
74isUsed moduleName graph vertexFor entryPointVertices (DataBindingGroupDeclaration ds) =
74isUsed moduleName graph vertexFor entryPointVertices (DataBindingGroupDeclaration ds) =
75 any (isUsed moduleName graph vertexFor entryPointVertices) ds
75 any (isUsed moduleName graph vertexFor entryPointVertices) ds
76isUsed _ _ _ _ _ = True
76isUsed _ _ _ _ _ = True
src/Language/PureScript/Declarations.hs+2−23
@@ -45,27 +45,6 @@ data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable
45--
45--
46data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
46data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
47
47
48−-- |
49−-- The type of a foreign import
50−--
51−data ForeignImportType
52− -- |
53− -- A regular foreign import
54− --
55− = ForeignImport
56− -- |
57− -- A foreign import which contains inline Javascript as a string literal
58− --
59− | InlineJavascript
60− -- |
61− -- A type class dictionary import, generated during desugaring of type class declarations
62− --
63− | TypeClassDictionaryImport
64− -- |
65− -- A type class dictionary member accessor import, generated during desugaring of type class declarations
66− --
67− | TypeClassAccessorImport deriving (Show, Eq, D.Data, D.Typeable)
68−
69-- |
48-- |
70-- An item in a list of explicit imports or exports
49-- An item in a list of explicit imports or exports
71--
50--
@@ -107,11 +86,11 @@ data Declaration
107 -- |
86 -- |
108 -- A value declaration (name, top-level binders, optional guard, value)
87 -- A value declaration (name, top-level binders, optional guard, value)
109 --
88 --
110− | ValueDeclaration Ident [Binder] (Maybe Guard) Value
89+ | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
111 -- |
90 -- |
112 -- A minimal mutually recursive set of value declarations
91 -- A minimal mutually recursive set of value declarations
113 --
92 --
114− | BindingGroupDeclaration [(Ident, Value)]
93+ | BindingGroupDeclaration [(Ident, NameKind, Value)]
115 -- |
94 -- |
116 -- A foreign import declaration (type, name, optional inline Javascript, type)
95 -- A foreign import declaration (type, name, optional inline Javascript, type)
117 --
96 --
src/Language/PureScript/Names.hs+46
@@ -21,6 +21,52 @@ import Data.List
21import Data.Data
21import Data.Data
22import Data.Function (on)
22import Data.Function (on)
23
23
24+-- |
25+-- The type of a foreign import
26+--
27+data ForeignImportType
28+ -- |
29+ -- A regular foreign import
30+ --
31+ = ForeignImport
32+ -- |
33+ -- A foreign import which contains inline Javascript as a string literal
34+ --
35+ | InlineJavascript
36+ -- |
37+ -- A type class dictionary member accessor import, generated during desugaring of type class declarations
38+ --
39+ | TypeClassAccessorImport deriving (Show, Eq, Data, Typeable)
40+
41+-- |
42+-- The type of a name
43+--
44+data NameKind
45+ -- |
46+ -- A value introduced as a binding in a module
47+ --
48+ = Value
49+ -- |
50+ -- A foreign import
51+ --
52+ | Extern ForeignImportType
53+ -- |
54+ -- A local name introduced using a lambda abstraction, variable introduction or binder
55+ --
56+ | LocalVariable
57+ -- |
58+ -- A data constructor
59+ --
60+ | DataConstructor
61+ -- |
62+ -- A type class dictionary, generated during desugaring of type class declarations
63+ --
64+ | TypeInstanceDictionaryValue
65+ -- |
66+ -- A type instance member, generated during desugaring of type class declarations
67+ --
68+ | TypeInstanceMember deriving (Show, Eq, Data, Typeable)
69+
24-- |
70-- |
25-- Names for value identifiers
71-- Names for value identifiers
26--
72--
src/Language/PureScript/Parser/Declarations.hs+2
@@ -29,6 +29,7 @@ import Language.PureScript.Declarations
29import Language.PureScript.Parser.Values
29import Language.PureScript.Parser.Values
30import Language.PureScript.Parser.Types
30import Language.PureScript.Parser.Types
31import Language.PureScript.Parser.Kinds
31import Language.PureScript.Parser.Kinds
32+import Language.PureScript.Names
32import Language.PureScript.CodeGen.JS.AST
33import Language.PureScript.CodeGen.JS.AST
33
34
34parseDataDeclaration :: P.Parsec String ParseState Declaration
35parseDataDeclaration :: P.Parsec String ParseState Declaration
@@ -55,6 +56,7 @@ parseTypeSynonymDeclaration =
55parseValueDeclaration :: P.Parsec String ParseState Declaration
56parseValueDeclaration :: P.Parsec String ParseState Declaration
56parseValueDeclaration =
57parseValueDeclaration =
57 ValueDeclaration <$> parseIdent
58 ValueDeclaration <$> parseIdent
59+ <*> pure Value
58 <*> P.many parseBinderNoParens
60 <*> P.many parseBinderNoParens
59 <*> P.optionMaybe parseGuard
61 <*> P.optionMaybe parseGuard
60 <*> (lexeme (indented *> P.char '=') *> parseValue)
62 <*> (lexeme (indented *> P.char '=') *> parseValue)
src/Language/PureScript/Pretty/Types.hs+28−12
@@ -20,7 +20,7 @@ module Language.PureScript.Pretty.Types (
20
20
21import Data.Maybe (fromMaybe)
21import Data.Maybe (fromMaybe)
22import Data.List (intercalate)
22import Data.List (intercalate)
23−import Data.Generics (mkT, everywhere)
23+import Data.Generics (mkT, everywhere, everywhere')
24
24
25import Control.Arrow ((<+>))
25import Control.Arrow ((<+>))
26import Control.PatternArrows
26import Control.PatternArrows
@@ -39,9 +39,9 @@ typeLiterals = mkPattern match
39 match (TypeConstructor ctor) = Just $ show ctor
39 match (TypeConstructor ctor) = Just $ show ctor
40 match (TUnknown (Unknown u)) = Just $ 'u' : show u
40 match (TUnknown (Unknown u)) = Just $ 'u' : show u
41 match (Skolem s _) = Just $ 's' : show s
41 match (Skolem s _) = Just $ 's' : show s
42− match (ConstrainedType deps ty) = Just $ "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ unwords (map prettyPrintType ty') ++ ")") deps) ++ ") => " ++ prettyPrintType ty
42+ match (ConstrainedType deps ty) = Just $ "(" ++ intercalate ", " (map (\(pn, ty') -> show pn ++ " " ++ unwords (map prettyPrintTypeAtom ty')) deps) ++ ") => " ++ prettyPrintType ty
43− match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintType args) ++ ">"
43+ match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintTypeAtom args) ++ ">"
44− match (ForAll ident ty _) = Just $ "forall " ++ ident ++ ". " ++ prettyPrintType ty
44+ match (PrettyPrintForAll idents ty) = Just $ "forall " ++ unwords idents ++ ". " ++ prettyPrintType ty
45 match REmpty = Just "()"
45 match REmpty = Just "()"
46 match row@RCons{} = Just $ '(' : prettyPrintRow row ++ ")"
46 match row@RCons{} = Just $ '(' : prettyPrintRow row ++ ")"
47 match _ = Nothing
47 match _ = Nothing
@@ -77,23 +77,39 @@ appliedFunction = mkPattern match
77 match _ = Nothing
77 match _ = Nothing
78
78
79insertPlaceholders :: Type -> Type
79insertPlaceholders :: Type -> Type
80−insertPlaceholders = everywhere (mkT convert)
80+insertPlaceholders = everywhere' (mkT convertForAlls) . everywhere (mkT convert)
81 where
81 where
82 convert (TypeApp (TypeApp f arg) ret) | f == tyFunction = PrettyPrintFunction arg ret
82 convert (TypeApp (TypeApp f arg) ret) | f == tyFunction = PrettyPrintFunction arg ret
83 convert (TypeApp a el) | a == tyArray = PrettyPrintArray el
83 convert (TypeApp a el) | a == tyArray = PrettyPrintArray el
84 convert other = other
84 convert other = other
85+ convertForAlls (ForAll ident ty _) = go [ident] ty
86+ where
87+ go idents (ForAll ident' ty' _) = go (ident' : idents) ty'
88+ go idents other = PrettyPrintForAll idents other
89+ convertForAlls other = other
85
90
86−-- |
91+matchTypeAtom :: Pattern () Type String
87−-- Generate a pretty-printed string representing a Type
92+matchTypeAtom = typeLiterals <+> fmap parens matchType
88−--
93+
89−prettyPrintType :: Type -> String
94+matchType :: Pattern () Type String
90−prettyPrintType = fromMaybe (error "Incomplete pattern") . pattern matchType () . insertPlaceholders
95+matchType = buildPrettyPrinter operators matchTypeAtom
91 where
96 where
92− matchType :: Pattern () Type String
93− matchType = buildPrettyPrinter operators (typeLiterals <+> fmap parens matchType)
94 operators :: OperatorTable () Type String
97 operators :: OperatorTable () Type String
95 operators =
98 operators =
96 OperatorTable [ [ AssocL typeApp $ \f x -> f ++ " " ++ x ]
99 OperatorTable [ [ AssocL typeApp $ \f x -> f ++ " " ++ x ]
97 , [ AssocR appliedFunction $ \arg ret -> arg ++ " -> " ++ ret
100 , [ AssocR appliedFunction $ \arg ret -> arg ++ " -> " ++ ret
98 ]
101 ]
99 ]
102 ]
103+
104+-- |
105+-- Generate a pretty-printed string representing a Type, as it should appear inside parentheses
106+--
107+prettyPrintTypeAtom :: Type -> String
108+prettyPrintTypeAtom = fromMaybe (error "Incomplete pattern") . pattern matchTypeAtom () . insertPlaceholders
109+
110+
111+-- |
112+-- Generate a pretty-printed string representing a Type
113+--
114+prettyPrintType :: Type -> String
115+prettyPrintType = fromMaybe (error "Incomplete pattern") . pattern matchType () . insertPlaceholders
src/Language/PureScript/Sugar/BindingGroups.hs+4−4
@@ -72,7 +72,7 @@ collapseBindingGroups :: [Declaration] -> [Declaration]
72collapseBindingGroups = concatMap go
72collapseBindingGroups = concatMap go
73 where
73 where
74 go (DataBindingGroupDeclaration ds) = ds
74 go (DataBindingGroupDeclaration ds) = ds
75− go (BindingGroupDeclaration ds) = map (\(ident, val) -> ValueDeclaration ident [] Nothing val) ds
75+ go (BindingGroupDeclaration ds) = map (\(ident, nameKind, val) -> ValueDeclaration ident nameKind [] Nothing val) ds
76 go other = [other]
76 go other = [other]
77
77
78usedIdents :: (Data d) => ModuleName -> d -> [Ident]
78usedIdents :: (Data d) => ModuleName -> d -> [Ident]
@@ -91,7 +91,7 @@ usedProperNames moduleName = nub . everything (++) (mkQ [] names)
91 names _ = []
91 names _ = []
92
92
93getIdent :: Declaration -> Ident
93getIdent :: Declaration -> Ident
94−getIdent (ValueDeclaration ident _ _ _) = ident
94+getIdent (ValueDeclaration ident _ _ _ _) = ident
95getIdent _ = error "Expected ValueDeclaration"
95getIdent _ = error "Expected ValueDeclaration"
96
96
97getProperName :: Declaration -> ProperName
97getProperName :: Declaration -> ProperName
@@ -115,7 +115,7 @@ toDataBindingGroup (CyclicSCC ds')
115 isTypeSynonym TypeSynonymDeclaration{} = True
115 isTypeSynonym TypeSynonymDeclaration{} = True
116 isTypeSynonym _ = False
116 isTypeSynonym _ = False
117
117
118−fromValueDecl :: Declaration -> (Ident, Value)
118+fromValueDecl :: Declaration -> (Ident, NameKind, Value)
119−fromValueDecl (ValueDeclaration ident [] Nothing val) = (ident, val)
119+fromValueDecl (ValueDeclaration ident nameKind [] Nothing val) = (ident, nameKind, val)
120fromValueDecl ValueDeclaration{} = error "Binders should have been desugared"
120fromValueDecl ValueDeclaration{} = error "Binders should have been desugared"
121fromValueDecl _ = error "Expected ValueDeclaration"
121fromValueDecl _ = error "Expected ValueDeclaration"
src/Language/PureScript/Sugar/CaseDeclarations.hs+5−5
@@ -60,12 +60,12 @@ desugarCases = desugarRest <=< fmap join . mapM toDecls . groupBy inSameGroup
60 desugarRest [] = pure []
60 desugarRest [] = pure []
61
61
62inSameGroup :: Declaration -> Declaration -> Bool
62inSameGroup :: Declaration -> Declaration -> Bool
63−inSameGroup (ValueDeclaration ident1 _ _ _) (ValueDeclaration ident2 _ _ _) = ident1 == ident2
63+inSameGroup (ValueDeclaration ident1 _ _ _ _) (ValueDeclaration ident2 _ _ _ _) = ident1 == ident2
64inSameGroup _ _ = False
64inSameGroup _ _ = False
65
65
66toDecls :: [Declaration] -> Either String [Declaration]
66toDecls :: [Declaration] -> Either String [Declaration]
67−toDecls d@[ValueDeclaration _ [] Nothing _] = return d
67+toDecls d@[ValueDeclaration _ _ [] Nothing _] = return d
68−toDecls ds@(ValueDeclaration ident bs _ _ : _) = do
68+toDecls ds@(ValueDeclaration ident _ bs _ _ : _) = do
69 let tuples = map toTuple ds
69 let tuples = map toTuple ds
70 unless (all ((== length bs) . length . fst) tuples) $
70 unless (all ((== length bs) . length . fst) tuples) $
71 throwError $ "Argument list lengths differ in declaration " ++ show ident
71 throwError $ "Argument list lengths differ in declaration " ++ show ident
@@ -73,7 +73,7 @@ toDecls ds@(ValueDeclaration ident bs _ _ : _) = do
73toDecls ds = return ds
73toDecls ds = return ds
74
74
75toTuple :: Declaration -> ([Binder], (Maybe Guard, Value))
75toTuple :: Declaration -> ([Binder], (Maybe Guard, Value))
76−toTuple (ValueDeclaration _ bs g val) = (bs, (g, val))
76+toTuple (ValueDeclaration _ _ bs g val) = (bs, (g, val))
77toTuple _ = error "Not a value declaration"
77toTuple _ = error "Not a value declaration"
78
78
79makeCaseDeclaration :: Ident -> [([Binder], (Maybe Guard, Value))] -> Declaration
79makeCaseDeclaration :: Ident -> [([Binder], (Maybe Guard, Value))] -> Declaration
@@ -85,5 +85,5 @@ makeCaseDeclaration ident alternatives =
85 binders = [ CaseAlternative bs g val | (bs, (g, val)) <- alternatives ]
85 binders = [ CaseAlternative bs g val | (bs, (g, val)) <- alternatives ]
86 value = foldr (\arg ret -> Abs (Left arg) ret) (Case vars binders) args
86 value = foldr (\arg ret -> Abs (Left arg) ret) (Case vars binders) args
87 in
87 in
88− ValueDeclaration ident [] Nothing value
88+ ValueDeclaration ident Value [] Nothing value
89
89
src/Language/PureScript/Sugar/Names.hs+4−4
@@ -170,8 +170,8 @@ renameInModule imports exports (Module mn decls exps) =
170 updateDecl d = return d
170 updateDecl d = return d
171
171
172 updateVars :: Declaration -> Either String Declaration
172 updateVars :: Declaration -> Either String Declaration
173− updateVars (ValueDeclaration name [] Nothing val) =
173+ updateVars (ValueDeclaration name nameKind [] Nothing val) =
174− ValueDeclaration name [] Nothing <$> everywhereWithContextM' [] (mkS bindFunctionArgs `extS` bindBinders) val
174+ ValueDeclaration name nameKind [] Nothing <$> everywhereWithContextM' [] (mkS bindFunctionArgs `extS` bindBinders) val
175 where
175 where
176 bindFunctionArgs bound (Abs (Left arg) val') = return (arg : bound, Abs (Left arg) val')
176 bindFunctionArgs bound (Abs (Left arg) val') = return (arg : bound, Abs (Left arg) val')
177 bindFunctionArgs bound (Var name'@(Qualified Nothing ident)) | ident `notElem` bound = (,) bound <$> (Var <$> updateValueName name')
177 bindFunctionArgs bound (Var name'@(Qualified Nothing ident)) | ident `notElem` bound = (,) bound <$> (Var <$> updateValueName name')
@@ -179,7 +179,7 @@ renameInModule imports exports (Module mn decls exps) =
179 bindFunctionArgs bound other = return (bound, other)
179 bindFunctionArgs bound other = return (bound, other)
180 bindBinders :: [Ident] -> CaseAlternative -> Either String ([Ident], CaseAlternative)
180 bindBinders :: [Ident] -> CaseAlternative -> Either String ([Ident], CaseAlternative)
181 bindBinders bound c@(CaseAlternative bs _ _) = return (binderNames bs ++ bound, c)
181 bindBinders bound c@(CaseAlternative bs _ _) = return (binderNames bs ++ bound, c)
182− updateVars (ValueDeclaration name _ _ _) = error $ "Binders should have been desugared in " ++ show name
182+ updateVars (ValueDeclaration name _ _ _ _) = error $ "Binders should have been desugared in " ++ show name
183 updateVars other = return other
183 updateVars other = return other
184 updateValue (Constructor name) = Constructor <$> updateDataConstructorName name
184 updateValue (Constructor name) = Constructor <$> updateDataConstructorName name
185 updateValue v = return v
185 updateValue v = return v
@@ -252,7 +252,7 @@ findExports = foldM addModule $ M.singleton (ModuleName [ProperName "Prim"]) pri
252 addDecl mn env (DataDeclaration tn _ dcs) = addType env mn tn (map fst dcs)
252 addDecl mn env (DataDeclaration tn _ dcs) = addType env mn tn (map fst dcs)
253 addDecl mn env (TypeSynonymDeclaration tn _ _) = addType env mn tn []
253 addDecl mn env (TypeSynonymDeclaration tn _ _) = addType env mn tn []
254 addDecl mn env (ExternDataDeclaration tn _) = addType env mn tn []
254 addDecl mn env (ExternDataDeclaration tn _) = addType env mn tn []
255− addDecl mn env (ValueDeclaration name _ _ _) = addValue env mn name
255+ addDecl mn env (ValueDeclaration name _ _ _ _) = addValue env mn name
256 addDecl mn env (ExternDeclaration _ name _ _) = addValue env mn name
256 addDecl mn env (ExternDeclaration _ name _ _) = addValue env mn name
257 addDecl _ env _ = return env
257 addDecl _ env _ = return env
258
258
src/Language/PureScript/Sugar/TypeClasses.hs+4−4
@@ -122,7 +122,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
122 let memberTypes = map (second (replaceAllTypeVars (zip args tys))) instanceTys
122 let memberTypes = map (second (replaceAllTypeVars (zip args tys))) instanceTys
123 let entryName = Escaped (show name)
123 let entryName = Escaped (show name)
124 memberNames <- mapM (memberToNameAndValue memberTypes) decls
124 memberNames <- mapM (memberToNameAndValue memberTypes) decls
125− return $ ValueDeclaration entryName [] Nothing
125+ return $ ValueDeclaration entryName TypeInstanceDictionaryValue [] Nothing
126 (TypedValue True
126 (TypedValue True
127 (foldr (Abs . (\n -> Left . Ident $ '_' : show n)) (ObjectLiteral memberNames) [1..max 1 (length deps)])
127 (foldr (Abs . (\n -> Left . Ident $ '_' : show n)) (ObjectLiteral memberNames) [1..max 1 (length deps)])
128 (quantify (if null deps then
128 (quantify (if null deps then
@@ -132,7 +132,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
132 )
132 )
133 where
133 where
134 memberToNameAndValue :: [(String, Type)] -> Declaration -> Desugar (String, Value)
134 memberToNameAndValue :: [(String, Type)] -> Declaration -> Desugar (String, Value)
135− memberToNameAndValue tys' (ValueDeclaration ident _ _ _) = do
135+ memberToNameAndValue tys' (ValueDeclaration ident _ _ _ _) = do
136 memberType <- lift . maybe (Left "Type class member type not found") Right $ lookup (identToJs ident) tys'
136 memberType <- lift . maybe (Left "Type class member type not found") Right $ lookup (identToJs ident) tys'
137 memberName <- mkDictionaryEntryName name ident
137 memberName <- mkDictionaryEntryName name ident
138 return (identToJs ident, TypedValue False
138 return (identToJs ident, TypedValue False
@@ -141,13 +141,13 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
141 memberToNameAndValue _ _ = error "Invalid declaration in type instance definition"
141 memberToNameAndValue _ _ = error "Invalid declaration in type instance definition"
142
142
143typeInstanceDictionaryEntryDeclaration :: Ident -> ModuleName -> [(Qualified ProperName, [Type])] -> Qualified ProperName -> [Type] -> Declaration -> Desugar Declaration
143typeInstanceDictionaryEntryDeclaration :: Ident -> ModuleName -> [(Qualified ProperName, [Type])] -> Qualified ProperName -> [Type] -> Declaration -> Desugar Declaration
144−typeInstanceDictionaryEntryDeclaration name mn deps className tys (ValueDeclaration ident [] _ val) = do
144+typeInstanceDictionaryEntryDeclaration name mn deps className tys (ValueDeclaration ident _ [] _ val) = do
145 m <- get
145 m <- get
146 valTy <- lift $ do (args, members) <- lookupTypeClass m
146 valTy <- lift $ do (args, members) <- lookupTypeClass m
147 ty' <- lookupIdent members
147 ty' <- lookupIdent members
148 return $ replaceAllTypeVars (zip args tys) ty'
148 return $ replaceAllTypeVars (zip args tys) ty'
149 entryName <- mkDictionaryEntryName name ident
149 entryName <- mkDictionaryEntryName name ident
150− return $ ValueDeclaration entryName [] Nothing
150+ return $ ValueDeclaration entryName TypeInstanceMember [] Nothing
151 (TypedValue True val (quantify (if null deps then valTy else ConstrainedType deps valTy)))
151 (TypedValue True val (quantify (if null deps then valTy else ConstrainedType deps valTy)))
152 where
152 where
153 lookupTypeClass m = maybe (Left $ "Type class " ++ show className ++ " is undefined. Type class names must be qualified.") Right $ M.lookup (qualify mn className) m
153 lookupTypeClass m = maybe (Left $ "Type class " ++ show className ++ " is undefined. Type class names must be qualified.") Right $ M.lookup (qualify mn className) m
src/Language/PureScript/Sugar/TypeDeclarations.hs+2−2
@@ -36,8 +36,8 @@ desugarTypeDeclarationsModule ms = forM ms $ \(Module name ds exps) -> Module na
36-- Replace all top level type declarations with type annotations
36-- Replace all top level type declarations with type annotations
37--
37--
38desugarTypeDeclarations :: [Declaration] -> Either String [Declaration]
38desugarTypeDeclarations :: [Declaration] -> Either String [Declaration]
39−desugarTypeDeclarations (TypeDeclaration name ty : ValueDeclaration name' [] Nothing val : rest) | name == name' =
39+desugarTypeDeclarations (TypeDeclaration name ty : ValueDeclaration name' nameKind [] Nothing val : rest) | name == name' =
40− desugarTypeDeclarations (ValueDeclaration name [] Nothing (TypedValue True val ty) : rest)
40+ desugarTypeDeclarations (ValueDeclaration name nameKind [] Nothing (TypedValue True val ty) : rest)
41desugarTypeDeclarations (TypeDeclaration name _ : _) = throwError $ "Orphan type declaration for " ++ show name
41desugarTypeDeclarations (TypeDeclaration name _ : _) = throwError $ "Orphan type declaration for " ++ show name
42desugarTypeDeclarations (d:ds) = (:) d <$> desugarTypeDeclarations ds
42desugarTypeDeclarations (d:ds) = (:) d <$> desugarTypeDeclarations ds
43desugarTypeDeclarations [] = return []
43desugarTypeDeclarations [] = return []
src/Language/PureScript/TypeChecker.hs+13−13
@@ -51,7 +51,7 @@ addDataConstructor moduleName name args dctor tys = do
51 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
51 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
52 let dctorTy = foldr function retTy tys
52 let dctorTy = foldr function retTy tys
53 let polyType = mkForAll args dctorTy
53 let polyType = mkForAll args dctorTy
54− putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) polyType (dataConstructors env) }
54+ putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) (name, polyType) (dataConstructors env) }
55
55
56addTypeSynonym :: ModuleName -> ProperName -> [String] -> Type -> Kind -> Check ()
56addTypeSynonym :: ModuleName -> ProperName -> [String] -> Type -> Kind -> Check ()
57addTypeSynonym moduleName name args ty kind = do
57addTypeSynonym moduleName name args ty kind = do
@@ -66,10 +66,10 @@ valueIsNotDefined moduleName name = do
66 Just _ -> throwError $ show name ++ " is already defined"
66 Just _ -> throwError $ show name ++ " is already defined"
67 Nothing -> return ()
67 Nothing -> return ()
68
68
69−addValue :: ModuleName -> Ident -> Type -> Check ()
69+addValue :: ModuleName -> Ident -> Type -> NameKind -> Check ()
70−addValue moduleName name ty = do
70+addValue moduleName name ty nameKind = do
71 env <- getEnv
71 env <- getEnv
72− putEnv (env { names = M.insert (moduleName, name) (ty, Value) (names env) })
72+ putEnv (env { names = M.insert (moduleName, name) (ty, nameKind) (names env) })
73
73
74addTypeClassDictionaries :: [TypeClassDictionaryInScope] -> Check ()
74addTypeClassDictionaries :: [TypeClassDictionaryInScope] -> Check ()
75addTypeClassDictionaries entries =
75addTypeClassDictionaries entries =
@@ -128,23 +128,23 @@ typeCheckAll mainModuleName moduleName (d@(TypeSynonymDeclaration name args ty)
128 ds <- typeCheckAll mainModuleName moduleName rest
128 ds <- typeCheckAll mainModuleName moduleName rest
129 return $ d : ds
129 return $ d : ds
130typeCheckAll _ _ (TypeDeclaration _ _ : _) = error "Type declarations should have been removed"
130typeCheckAll _ _ (TypeDeclaration _ _ : _) = error "Type declarations should have been removed"
131−typeCheckAll mainModuleName moduleName (ValueDeclaration name [] Nothing val : rest) = do
131+typeCheckAll mainModuleName moduleName (ValueDeclaration name nameKind [] Nothing val : rest) = do
132 d <- rethrow (("Error in declaration " ++ show name ++ ":\n") ++) $ do
132 d <- rethrow (("Error in declaration " ++ show name ++ ":\n") ++) $ do
133 valueIsNotDefined moduleName name
133 valueIsNotDefined moduleName name
134 [(_, (val', ty))] <- typesOf mainModuleName moduleName [(name, val)]
134 [(_, (val', ty))] <- typesOf mainModuleName moduleName [(name, val)]
135− addValue moduleName name ty
135+ addValue moduleName name ty nameKind
136− return $ ValueDeclaration name [] Nothing val'
136+ return $ ValueDeclaration name nameKind [] Nothing val'
137 ds <- typeCheckAll mainModuleName moduleName rest
137 ds <- typeCheckAll mainModuleName moduleName rest
138 return $ d : ds
138 return $ d : ds
139typeCheckAll _ _ (ValueDeclaration{} : _) = error "Binders were not desugared"
139typeCheckAll _ _ (ValueDeclaration{} : _) = error "Binders were not desugared"
140typeCheckAll mainModuleName moduleName (BindingGroupDeclaration vals : rest) = do
140typeCheckAll mainModuleName moduleName (BindingGroupDeclaration vals : rest) = do
141− d <- rethrow (("Error in binding group " ++ show (map fst vals) ++ ":\n") ++) $ do
141+ d <- rethrow (("Error in binding group " ++ show (map (\(ident, _, _) -> ident) vals) ++ ":\n") ++) $ do
142− forM_ (map fst vals) $ \name ->
142+ forM_ (map (\(ident, _, _) -> ident) vals) $ \name ->
143 valueIsNotDefined moduleName name
143 valueIsNotDefined moduleName name
144− tys <- typesOf mainModuleName moduleName vals
144+ tys <- typesOf mainModuleName moduleName $ map (\(ident, _, ty) -> (ident, ty)) vals
145− vals' <- forM (zip (map fst vals) (map snd tys)) $ \(name, (val, ty)) -> do
145+ vals' <- forM (zipWith (\(name, nameKind, _) (_, (val, ty)) -> (name, val, nameKind, ty)) vals tys) $ \(name, val, nameKind, ty) -> do
146− addValue moduleName name ty
146+ addValue moduleName name ty nameKind
147− return (name, val)
147+ return (name, nameKind, val)
148 return $ BindingGroupDeclaration vals'
148 return $ BindingGroupDeclaration vals'
149 ds <- typeCheckAll mainModuleName moduleName rest
149 ds <- typeCheckAll mainModuleName moduleName rest
150 return $ d : ds
150 return $ d : ds
src/Language/PureScript/TypeChecker/Kinds.hs+1−1
@@ -74,7 +74,7 @@ kindsOf moduleName name args ts = fmap tidyUp . liftUnify $ do
74 bindLocalTypeVariables moduleName dict $
74 bindLocalTypeVariables moduleName dict $
75 solveTypes ts kargs tyCon
75 solveTypes ts kargs tyCon
76 where
76 where
77− tidyUp (k, sub) = sub $? k
77+ tidyUp (k, sub) = starIfUnknown $ sub $? k
78
78
79-- |
79-- |
80-- Simultaneously infer the kinds of several mutually recursive type constructors
80-- Simultaneously infer the kinds of several mutually recursive type constructors
src/Language/PureScript/TypeChecker/Monad.hs+1−23
@@ -22,7 +22,6 @@ import Language.PureScript.Types
22import Language.PureScript.Kinds
22import Language.PureScript.Kinds
23import Language.PureScript.Values
23import Language.PureScript.Values
24import Language.PureScript.Names
24import Language.PureScript.Names
25−import Language.PureScript.Declarations
26import Language.PureScript.Prim
25import Language.PureScript.Prim
27
26
28import Data.Maybe
27import Data.Maybe
@@ -35,27 +34,6 @@ import Control.Arrow (first)
35
34
36import qualified Data.Map as M
35import qualified Data.Map as M
37
36
38−-- |
39−-- The type of a name in the @Environment@
40−--
41−data NameKind
42− -- |
43− -- A value introduced as a binding in a module
44− --
45− = Value
46− -- |
47− -- A foreign import
48− --
49− | Extern ForeignImportType
50− -- |
51− -- A local name introduced using a lambda abstraction, variable introduction or binder
52− --
53− | LocalVariable
54− -- |
55− -- A data constructor
56− --
57− | DataConstructor deriving Show
58−
59-- |
37-- |
60-- The @Environment@ defines all values and types which are currently in scope:
38-- The @Environment@ defines all values and types which are currently in scope:
61--
39--
@@ -71,7 +49,7 @@ data Environment = Environment {
71 -- |
49 -- |
72 -- Data constructors currently in scope, along with their associated data type constructors
50 -- Data constructors currently in scope, along with their associated data type constructors
73 --
51 --
74− , dataConstructors :: M.Map (Qualified ProperName) Type
52+ , dataConstructors :: M.Map (Qualified ProperName) (ProperName, Type)
75 -- |
53 -- |
76 -- Type synonyms currently in scope
54 -- Type synonyms currently in scope
77 --
55 --
src/Language/PureScript/TypeChecker/Types.hs+4−4
@@ -533,8 +533,8 @@ infer' v@(Constructor c) = do
533 env <- getEnv
533 env <- getEnv
534 case M.lookup c (dataConstructors env) of
534 case M.lookup c (dataConstructors env) of
535 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
535 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
536− Just ty -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
536+ Just (_, ty) -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
537− return $ TypedValue True v ty'
537+ return $ TypedValue True v ty'
538infer' (Case vals binders) = do
538infer' (Case vals binders) = do
539 ts <- mapM infer vals
539 ts <- mapM infer vals
540 ret <- fresh
540 ret <- fresh
@@ -582,7 +582,7 @@ inferBinder val (VarBinder name) = return $ M.singleton name val
582inferBinder val (ConstructorBinder ctor binders) = do
582inferBinder val (ConstructorBinder ctor binders) = do
583 env <- getEnv
583 env <- getEnv
584 case M.lookup ctor (dataConstructors env) of
584 case M.lookup ctor (dataConstructors env) of
585− Just ty -> do
585+ Just (_, ty) -> do
586 (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contains constraints") ty
586 (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contains constraints") ty
587 go binders fn
587 go binders fn
588 where
588 where
@@ -778,7 +778,7 @@ check' (Constructor c) ty = do
778 env <- getEnv
778 env <- getEnv
779 case M.lookup c (dataConstructors env) of
779 case M.lookup c (dataConstructors env) of
780 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
780 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
781− Just ty1 -> do
781+ Just (_, ty1) -> do
782 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
782 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
783 _ <- subsumes Nothing repl ty
783 _ <- subsumes Nothing repl ty
784 return $ TypedValue True (Constructor c) ty
784 return $ TypedValue True (Constructor c) ty
src/Language/PureScript/Types.hs+5−1
@@ -86,7 +86,11 @@ data Type
86 -- |
86 -- |
87 -- A placeholder used in pretty printing
87 -- A placeholder used in pretty printing
88 --
88 --
89− | PrettyPrintArray Type deriving (Show, Eq, Data, Typeable)
89+ | PrettyPrintArray Type
90+ -- |
91+ -- A placeholder used in pretty printing
92+ --
93+ | PrettyPrintForAll [String] Type deriving (Show, Eq, Data, Typeable)
90
94
91-- |
95-- |
92-- Convert a row to a list of pairs of labels and types
96-- Convert a row to a list of pairs of labels and types