git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
A start on #253
commit2e0c57ddc007ea796c0beb6685fd5171c95cad60 authorPhil Freeman <paf31@cantab.net> dateThu 6 Mar 2014, 22:56 (13 years ago) parentd3f05e6
20 files changed+294−253
docs/source/prelude.rst+56−56 prelude/README.md+56−56 psci/Main.hs+4−4 src/Language/PureScript/CodeGen/Externs.hs+42−23 src/Language/PureScript/CodeGen/JS.hs+10−13 src/Language/PureScript/DeadCodeElimination.hs+5−5 src/Language/PureScript/Declarations.hs+2−23 src/Language/PureScript/Names.hs+46 src/Language/PureScript/Parser/Declarations.hs+2 src/Language/PureScript/Pretty/Types.hs+28−12 src/Language/PureScript/Sugar/BindingGroups.hs+4−4 src/Language/PureScript/Sugar/CaseDeclarations.hs+5−5 src/Language/PureScript/Sugar/Names.hs+4−4 src/Language/PureScript/Sugar/TypeClasses.hs+4−4 src/Language/PureScript/Sugar/TypeDeclarations.hs+2−2 src/Language/PureScript/TypeChecker.hs+13−13 src/Language/PureScript/TypeChecker/Kinds.hs+1−1 src/Language/PureScript/TypeChecker/Monad.hs+1−23 src/Language/PureScript/TypeChecker/Types.hs+4−4 src/Language/PureScript/Types.hs+5−1
docs/source/prelude.rst+56−56
@@ -18,7 +18,7 @@ Type Classes
1818
1919 class Applicative f where
2020 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
2222
2323 class Bits b where
2424 (&) :: b -> b -> b
@@ -36,19 +36,19 @@ Type Classes
3636
3737 class Category a where
3838 id :: forall t. a t t
39− (<<<) :: forall d. forall c. forall b. 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
39+ (<<<) :: forall b c d. a c d -> a b c -> a b d
40+ (>>>) :: forall b c d. a b c -> a c d -> a b d
4141
4242 class Eq a where
4343 (==) :: a -> a -> Prim.Boolean
4444 (/=) :: a -> a -> Prim.Boolean
4545
4646 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
4848
4949 class Monad m where
5050 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
5252
5353 class Num a where
5454 (+) :: a -> a -> a
@@ -116,9 +116,9 @@ Values
116116
117117 (!!) :: forall a. [a] -> Prim.Number -> a
118118
119− (#) :: forall b. forall a. a -> (a -> b) -> b
119+ (#) :: forall a b. a -> (a -> b) -> b
120120
121− ($) :: forall b. forall a. (a -> b) -> a -> b
121+ ($) :: forall a b. (a -> b) -> a -> b
122122
123123 (++) :: Prim.String -> Prim.String -> Prim.String
124124
@@ -128,9 +128,9 @@ Values
128128
129129 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
130130
131− const :: forall b. forall a. a -> b -> a
131+ const :: forall a b. a -> b -> a
132132
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
134134
135135 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
136136
@@ -203,7 +203,7 @@ Values
203203
204204::
205205
206− mconcat :: forall m. (Monoid (m)) => [m] -> m
206+ mconcat :: forall m. (Monoid m) => [m] -> m
207207
208208Module Control.Monad
209209--------------------
@@ -222,23 +222,23 @@ Values
222222
223223::
224224
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
226226
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
228228
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
230230
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
232232
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]
234234
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]
236236
237− sequence :: forall a. forall m. (Monad (m)) => [m a] -> m [a]
237+ sequence :: forall m a. (Monad m) => [m a] -> m [a]
238238
239− when :: forall m. (Monad (m)) => Prim.Boolean -> m { } -> m { }
239+ when :: forall m. (Monad m) => Prim.Boolean -> m { } -> m { }
240240
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]
242242
243243Module Data.Maybe
244244-----------------
@@ -275,7 +275,7 @@ Values
275275
276276 fromMaybe :: forall a. a -> Maybe a -> a
277277
278− maybe :: forall b. forall a. b -> (a -> b) -> Maybe a -> b
278+ maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
279279
280280Module Data.Either
281281------------------
@@ -310,7 +310,7 @@ Values
310310
311311::
312312
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
314314
315315Module Data.Array
316316-----------------
@@ -347,7 +347,7 @@ Values
347347
348348 concat :: forall a. [a] -> [a] -> [a]
349349
350− concatMap :: forall b. forall a. [a] -> (a -> [b]) -> [b]
350+ concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
351351
352352 deleteAt :: forall a. Prim.Number -> Prim.Number -> [a] -> [a]
353353
@@ -357,9 +357,9 @@ Values
357357
358358 find :: forall a. (a -> Prim.Boolean) -> [a] -> Maybe a
359359
360− foldl :: forall b. forall a. (b -> a -> b) -> b -> [a] -> b
360+ foldl :: forall a b. (b -> a -> b) -> b -> [a] -> b
361361
362− foldr :: forall b. forall a. (a -> b -> a) -> a -> [b] -> a
362+ foldr :: forall a b. (a -> b -> a) -> a -> [b] -> a
363363
364364 head :: forall a. [a] -> Maybe a
365365
@@ -377,7 +377,7 @@ Values
377377
378378 length :: forall a. [a] -> Prim.Number
379379
380− map :: forall b. forall a. (a -> b) -> [a] -> [b]
380+ map :: forall a b. (a -> b) -> [a] -> [b]
381381
382382 push :: forall a. [a] -> a -> [a]
383383
@@ -399,7 +399,7 @@ Values
399399
400400 updateAt :: forall a. Prim.Number -> a -> [a] -> [a]
401401
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]
403403
404404Module Data.Eq
405405--------------
@@ -427,7 +427,7 @@ Values
427427
428428::
429429
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
431431
432432 refEq :: forall a. Ref a -> Ref a -> Prim.Boolean
433433
@@ -480,13 +480,13 @@ Values
480480
481481::
482482
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
484484
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
486486
487− unzip :: forall b. forall a. [Tuple a b] -> Tuple [a] [b]
487+ unzip :: forall a b. [Tuple a b] -> Tuple [a] [b]
488488
489− zip :: forall b. forall a. [a] -> [b] -> [Tuple a b]
489+ zip :: forall a b. [a] -> [b] -> [Tuple a b]
490490
491491Module Data.String
492492------------------
@@ -652,13 +652,13 @@ Values
652652
653653 log2e :: Prim.Number
654654
655− max :: Prim.Number -> Prim.Number
655+ max :: Prim.Number -> Prim.Number -> Prim.Number
656656
657− min :: Prim.Number -> Prim.Number
657+ min :: Prim.Number -> Prim.Number -> Prim.Number
658658
659659 pi :: Prim.Number
660660
661− pow :: Prim.Number -> Prim.Number
661+ pow :: Prim.Number -> Prim.Number -> Prim.Number
662662
663663 round :: Prim.Number -> Prim.Number
664664
@@ -699,19 +699,19 @@ Values
699699
700700::
701701
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
703703
704704 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
705705
706− foreachE :: forall a. forall e. [a] -> (a -> Eff e { }) -> Eff e { }
706+ foreachE :: forall e a. [a] -> (a -> Eff e { }) -> Eff e { }
707707
708− retEff :: forall a. forall e. a -> Eff e a
708+ retEff :: forall e a. a -> Eff e a
709709
710710 runPure :: forall a. Pure a -> a
711711
712712 untilE :: forall e. Eff e Prim.Boolean -> Eff e { }
713713
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 { }
715715
716716Module Control.Monad.Eff.Unsafe
717717-------------------------------
@@ -730,7 +730,7 @@ Values
730730
731731::
732732
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
734734
735735Module Random
736736-------------
@@ -776,9 +776,9 @@ Values
776776
777777::
778778
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
780780
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
782782
783783Module Data.IORef
784784-----------------
@@ -803,15 +803,15 @@ Values
803803
804804::
805805
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) { }
807807
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)
809809
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
811811
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
813813
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) { }
815815
816816Module Debug.Trace
817817------------------
@@ -834,7 +834,7 @@ Values
834834
835835::
836836
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) { }
838838
839839 trace :: forall r. Prim.String -> Eff (trace :: Trace | r) { }
840840
@@ -863,23 +863,23 @@ Values
863863
864864::
865865
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
867867
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)
869869
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)
871871
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
873873
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
875875
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
877877
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
879879
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]
881881
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
883883
884884Module Data.Enum
885885----------------
prelude/README.md+56−56
@@ -12,7 +12,7 @@
1212
1313 class Applicative f where
1414 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
1616
1717 class Bits b where
1818 (&) :: b -> b -> b
@@ -30,19 +30,19 @@
3030
3131 class Category a where
3232 id :: forall t. a t t
33− (<<<) :: forall d. forall c. forall b. 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
33+ (<<<) :: forall b c d. a c d -> a b c -> a b d
34+ (>>>) :: forall b c d. a b c -> a c d -> a b d
3535
3636 class Eq a where
3737 (==) :: a -> a -> Prim.Boolean
3838 (/=) :: a -> a -> Prim.Boolean
3939
4040 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
4242
4343 class Monad m where
4444 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
4646
4747 class Num a where
4848 (+) :: a -> a -> a
@@ -106,9 +106,9 @@
106106
107107 (!!) :: forall a. [a] -> Prim.Number -> a
108108
109− (#) :: forall b. forall a. a -> (a -> b) -> b
109+ (#) :: forall a b. a -> (a -> b) -> b
110110
111− ($) :: forall b. forall a. (a -> b) -> a -> b
111+ ($) :: forall a b. (a -> b) -> a -> b
112112
113113 (++) :: Prim.String -> Prim.String -> Prim.String
114114
@@ -118,9 +118,9 @@
118118
119119 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
120120
121− const :: forall b. forall a. a -> b -> a
121+ const :: forall a b. a -> b -> a
122122
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
124124
125125 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
126126
@@ -186,7 +186,7 @@
186186
187187### Values
188188
189− mconcat :: forall m. (Monoid (m)) => [m] -> m
189+ mconcat :: forall m. (Monoid m) => [m] -> m
190190
191191
192192## Module Control.Monad
@@ -202,23 +202,23 @@
202202
203203### Values
204204
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
206206
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
208208
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
210210
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
212212
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]
214214
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]
216216
217− sequence :: forall a. forall m. (Monad (m)) => [m a] -> m [a]
217+ sequence :: forall m a. (Monad m) => [m a] -> m [a]
218218
219− when :: forall m. (Monad (m)) => Prim.Boolean -> m { } -> m { }
219+ when :: forall m. (Monad m) => Prim.Boolean -> m { } -> m { }
220220
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]
222222
223223
224224## Module Data.Maybe
@@ -248,7 +248,7 @@
248248
249249 fromMaybe :: forall a. a -> Maybe a -> a
250250
251− maybe :: forall b. forall a. b -> (a -> b) -> Maybe a -> b
251+ maybe :: forall a b. b -> (a -> b) -> Maybe a -> b
252252
253253
254254## Module Data.Either
@@ -276,7 +276,7 @@
276276
277277### Values
278278
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
280280
281281
282282## Module Data.Array
@@ -308,7 +308,7 @@
308308
309309 concat :: forall a. [a] -> [a] -> [a]
310310
311− concatMap :: forall b. forall a. [a] -> (a -> [b]) -> [b]
311+ concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
312312
313313 deleteAt :: forall a. Prim.Number -> Prim.Number -> [a] -> [a]
314314
@@ -318,9 +318,9 @@
318318
319319 find :: forall a. (a -> Prim.Boolean) -> [a] -> Maybe a
320320
321− foldl :: forall b. forall a. (b -> a -> b) -> b -> [a] -> b
321+ foldl :: forall a b. (b -> a -> b) -> b -> [a] -> b
322322
323− foldr :: forall b. forall a. (a -> b -> a) -> a -> [b] -> a
323+ foldr :: forall a b. (a -> b -> a) -> a -> [b] -> a
324324
325325 head :: forall a. [a] -> Maybe a
326326
@@ -338,7 +338,7 @@
338338
339339 length :: forall a. [a] -> Prim.Number
340340
341− map :: forall b. forall a. (a -> b) -> [a] -> [b]
341+ map :: forall a b. (a -> b) -> [a] -> [b]
342342
343343 push :: forall a. [a] -> a -> [a]
344344
@@ -360,7 +360,7 @@
360360
361361 updateAt :: forall a. Prim.Number -> a -> [a] -> [a]
362362
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]
364364
365365
366366## Module Data.Eq
@@ -381,7 +381,7 @@
381381
382382### Values
383383
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
385385
386386 refEq :: forall a. Ref a -> Ref a -> Prim.Boolean
387387
@@ -424,13 +424,13 @@
424424
425425### Values
426426
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
428428
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
430430
431− unzip :: forall b. forall a. [Tuple a b] -> Tuple [a] [b]
431+ unzip :: forall a b. [Tuple a b] -> Tuple [a] [b]
432432
433− zip :: forall b. forall a. [a] -> [b] -> [Tuple a b]
433+ zip :: forall a b. [a] -> [b] -> [Tuple a b]
434434
435435
436436## Module Data.String
@@ -582,13 +582,13 @@
582582
583583 log2e :: Prim.Number
584584
585− max :: Prim.Number -> Prim.Number
585+ max :: Prim.Number -> Prim.Number -> Prim.Number
586586
587− min :: Prim.Number -> Prim.Number
587+ min :: Prim.Number -> Prim.Number -> Prim.Number
588588
589589 pi :: Prim.Number
590590
591− pow :: Prim.Number -> Prim.Number
591+ pow :: Prim.Number -> Prim.Number -> Prim.Number
592592
593593 round :: Prim.Number -> Prim.Number
594594
@@ -622,19 +622,19 @@
622622
623623### Values
624624
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
626626
627627 forE :: forall e. Prim.Number -> Prim.Number -> (Prim.Number -> Eff e { }) -> Eff e { }
628628
629− foreachE :: forall a. forall e. [a] -> (a -> Eff e { }) -> Eff e { }
629+ foreachE :: forall e a. [a] -> (a -> Eff e { }) -> Eff e { }
630630
631− retEff :: forall a. forall e. a -> Eff e a
631+ retEff :: forall e a. a -> Eff e a
632632
633633 runPure :: forall a. Pure a -> a
634634
635635 untilE :: forall e. Eff e Prim.Boolean -> Eff e { }
636636
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 { }
638638
639639
640640## Module Control.Monad.Eff.Unsafe
@@ -650,7 +650,7 @@
650650
651651### Values
652652
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
654654
655655
656656## Module Random
@@ -686,9 +686,9 @@
686686
687687### Values
688688
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
690690
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
692692
693693
694694## Module Data.IORef
@@ -708,15 +708,15 @@
708708
709709### Values
710710
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) { }
712712
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)
714714
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
716716
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
718718
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) { }
720720
721721
722722## Module Debug.Trace
@@ -734,7 +734,7 @@
734734
735735### Values
736736
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) { }
738738
739739 trace :: forall r. Prim.String -> Eff (trace :: Trace | r) { }
740740
@@ -758,23 +758,23 @@
758758
759759### Values
760760
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
762762
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)
764764
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)
766766
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
768768
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
770770
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
772772
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
774774
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]
776776
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
778778
779779
780780## Module Data.Enum
psci/Main.hs+4−4
@@ -173,8 +173,8 @@ completion = completeWord Nothing " \t\n\r" findCompletions
173173 let matches = filter (isPrefixOf str) (names ms)
174174 return $ sortBy sorter $ map simpleCompletion matches ++ files
175175 getDeclName :: Maybe [P.DeclarationRef] -> P.Declaration -> Maybe P.Ident
176− getDeclName Nothing (P.ValueDeclaration ident _ _ _) = Just ident
177− getDeclName (Just exts) (P.ValueDeclaration ident _ _ _) | isExported = Just ident
176+ getDeclName Nothing (P.ValueDeclaration ident _ _ _ _) = Just ident
177+ getDeclName (Just exts) (P.ValueDeclaration ident _ _ _ _) | isExported = Just ident
178178 where
179179 isExported = flip any exts $ \e -> case e of
180180 P.ValueRef ident' -> ident == ident'
@@ -209,8 +209,8 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
209209 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
210210 itValue = foldl (\x f -> f x) value lets
211211 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
212− itDecl = P.ValueDeclaration (P.Ident "it") [] Nothing itValue
213− mainDecl = P.ValueDeclaration (P.Ident "main") [] Nothing mainValue
212+ itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] Nothing itValue
213+ mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] Nothing mainValue
214214 decls = if exec then [itDecl, mainDecl] else [itDecl]
215215 in
216216 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 (
1717 moduleToPs
1818) where
1919
20−import Data.Maybe (maybeToList, mapMaybe)
20+import Data.List (intercalate)
21+
2122import qualified Data.Map as M
23+
24+import Control.Monad.Writer
25+
2226import Language.PureScript.Declarations
2327import Language.PureScript.TypeChecker.Monad
2428import Language.PureScript.Pretty
2529import Language.PureScript.Names
26−import Data.List (intercalate)
30+import Language.PureScript.Types
31+import Language.PureScript.Kinds
2732
2833-- |
2934-- Generate foreign imports for all declarations in a module
30−-- TODO: only expose items listed in "exps"
3135--
3236moduleToPs :: Module -> Environment -> String
33−moduleToPs (Module mn decls _) env =
34− "module " ++ runModuleName mn ++ " where\n" ++
35− (intercalate "\n" . map (" " ++) . concatMap (declToPs mn env) $ decls)
36−
37−declToPs :: ModuleName -> Environment -> Declaration -> [String]
38−declToPs path env (ValueDeclaration name _ _ _) = maybeToList $ do
39− (ty, _) <- M.lookup (path, name) $ names env
40− return $ "foreign import " ++ show name ++ " :: " ++ prettyPrintType ty
41−declToPs path env (BindingGroupDeclaration vals) =
42− flip mapMaybe vals $ \(name, _) -> do
43− (ty, _) <- M.lookup (path, name) $ names env
44− return $ "foreign import " ++ show name ++ " :: " ++ prettyPrintType ty
45−declToPs path env (DataDeclaration name _ _) = maybeToList $ do
46− kind <- M.lookup (Qualified (Just path) name) $ types env
47− return $ "foreign import data " ++ show name ++ " :: " ++ prettyPrintKind kind
48−declToPs _ _ (ExternDataDeclaration name kind) =
49− return $ "foreign import data " ++ show name ++ " :: " ++ prettyPrintKind kind
50−declToPs _ _ (TypeSynonymDeclaration name args ty) =
51− return $ "type " ++ show name ++ " " ++ unwords args ++ " = " ++ prettyPrintType ty
52−declToPs _ _ _ = []
37+moduleToPs (Module moduleName _ exts) env = intercalate "\n" . execWriter $ do
38+ tell ["module " ++ runModuleName moduleName ++ " where"]
39+ let typesExported = getTypesExportedFrom moduleName exts env
40+ forM_ typesExported $ \(pn, kind) ->
41+ tell ["foreign import data " ++ show pn ++ " :: " ++ prettyPrintKind kind]
42+ let namesExported = getNamesExportedFrom moduleName exts env
43+ forM_ namesExported $ \(ident, ty) ->
44+ tell ["foreign import " ++ show ident ++ " :: " ++ prettyPrintType ty]
45+
46+getNamesExportedFrom :: ModuleName -> Maybe [DeclarationRef] -> Environment -> [(Ident, Type)]
47+getNamesExportedFrom moduleName exps env =
48+ [ (ident, ty)
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)
62+ | ((Qualified (Just moduleName') pn), kind) <- M.toList . types $ env
63+ , moduleName == moduleName'
64+ , isExported pn exps
65+ ]
66+ where
67+ isExported :: ProperName -> Maybe [DeclarationRef] -> Bool
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)
3030
3131import qualified Data.Map as M
3232
33−import Language.PureScript.TypeChecker (Environment(..), NameKind(..))
33+import Language.PureScript.TypeChecker (Environment(..))
3434import Language.PureScript.Values
3535import Language.PureScript.Names
3636import Language.PureScript.Scope
@@ -62,10 +62,10 @@ moduleToJs opts (Module name decls _) env =
6262-- Generate code in the simplified Javascript intermediate representation for a declaration
6363--
6464declToJs :: Options -> ModuleName -> Declaration -> Environment -> Maybe [JS]
65−declToJs opts mp (ValueDeclaration ident _ _ val) e =
65+declToJs opts mp (ValueDeclaration ident _ _ _ val) e =
6666 Just $ export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
6767declToJs opts mp (BindingGroupDeclaration vals) e =
68− Just $ concatMap (\(ident, val) ->
68+ Just $ concatMap (\(ident, _, val) ->
6969 export ident $ JSVariableIntroduction (identToJs ident) (Just (valueToJs opts mp e val))
7070 ) vals
7171declToJs _ mp (DataDeclaration _ _ ctors) _ =
@@ -231,7 +231,7 @@ binderToJs _ _ varName done (VarBinder ident) =
231231 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : done)
232232binderToJs m e varName done (ConstructorBinder ctor bs) = do
233233 js <- go 0 done bs
234− if isOnlyConstructor m e ctor
234+ if isOnlyConstructor e ctor
235235 then
236236 return js
237237 else
@@ -284,17 +284,14 @@ binderToJs m e varName done (NamedBinder ident binder) = do
284284-- Checks whether a data constructor is the only constructor for that type, used to simplify the
285285-- check when generating code for binders.
286286--
287−isOnlyConstructor :: ModuleName -> Environment -> Qualified ProperName -> Bool
288−isOnlyConstructor m e ctor =
287+isOnlyConstructor :: Environment -> Qualified ProperName -> Bool
288+isOnlyConstructor e ctor =
289289 let ty = fromMaybe (error "Data constructor not found") $ ctor `M.lookup` dataConstructors e
290− in numConstructors ty == 1
290+ in numConstructors (ctor, ty) == 1
291291 where
292− numConstructors ty = length $ filter (((==) `on` typeConstructor) ty) $ M.elems $ dataConstructors e
293− typeConstructor (TypeConstructor qual) = qualify m qual
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
292+ numConstructors ty = length $ filter (((==) `on` typeConstructor) ty) $ M.toList $ dataConstructors e
293+ typeConstructor (Qualified (Just moduleName) _, (tyCtor, _)) = (moduleName, tyCtor)
294+ typeConstructor _ = error "Invalid argument to isOnlyConstructor"
298295
299296wrapExportsContainer :: Options -> [JS] -> JS
300297wrapExportsContainer 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])]
4242declarationsByModule (Module moduleName ds _) = concatMap go ds
4343 where
4444 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)]
4646 go (DataDeclaration _ _ dctors) = map (\(name, _) -> ((moduleName, Right name), [])) dctors
4747 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'
4949 go (DataBindingGroupDeclaration ds') = concatMap go ds'
5050 go _ = []
5151
@@ -59,7 +59,7 @@ dependencies moduleName = nub . everything (++) (mkQ [] values)
5959 values _ = []
6060
6161isUsed :: ModuleName -> Graph -> (Key -> Maybe Vertex) -> [Vertex] -> Declaration -> Bool
62−isUsed moduleName graph vertexFor entryPointVertices (ValueDeclaration name _ _ _) =
62+isUsed moduleName graph vertexFor entryPointVertices (ValueDeclaration name _ _ _ _) =
6363 let Just v' = vertexFor (moduleName, Left name)
6464 in any (\v -> path graph v v') entryPointVertices
6565isUsed moduleName graph vertexFor entryPointVertices (DataDeclaration _ _ dctors) =
@@ -69,8 +69,8 @@ isUsed moduleName graph vertexFor entryPointVertices (ExternDeclaration _ name _
6969 let Just v' = vertexFor (moduleName, Left name)
7070 in any (\v -> path graph v v') entryPointVertices
7171isUsed moduleName graph vertexFor entryPointVertices (BindingGroupDeclaration ds) =
72− any (\(name, _) -> let Just v' = vertexFor (moduleName, Left name)
73− in any (\v -> path graph v v') entryPointVertices) ds
72+ any (\(name, _, _) -> let Just v' = vertexFor (moduleName, Left name)
73+ in any (\v -> path graph v v') entryPointVertices) ds
7474isUsed moduleName graph vertexFor entryPointVertices (DataBindingGroupDeclaration ds) =
7575 any (isUsed moduleName graph vertexFor entryPointVertices) ds
7676isUsed _ _ _ _ _ = True
src/Language/PureScript/Declarations.hs+2−23
@@ -45,27 +45,6 @@ data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable
4545--
4646data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
4747
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−
6948-- |
7049-- An item in a list of explicit imports or exports
7150--
@@ -107,11 +86,11 @@ data Declaration
10786 -- |
10887 -- A value declaration (name, top-level binders, optional guard, value)
10988 --
110− | ValueDeclaration Ident [Binder] (Maybe Guard) Value
89+ | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
11190 -- |
11291 -- A minimal mutually recursive set of value declarations
11392 --
114− | BindingGroupDeclaration [(Ident, Value)]
93+ | BindingGroupDeclaration [(Ident, NameKind, Value)]
11594 -- |
11695 -- A foreign import declaration (type, name, optional inline Javascript, type)
11796 --
src/Language/PureScript/Names.hs+46
@@ -21,6 +21,52 @@ import Data.List
2121import Data.Data
2222import Data.Function (on)
2323
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+
2470-- |
2571-- Names for value identifiers
2672--
src/Language/PureScript/Parser/Declarations.hs+2
@@ -29,6 +29,7 @@ import Language.PureScript.Declarations
2929import Language.PureScript.Parser.Values
3030import Language.PureScript.Parser.Types
3131import Language.PureScript.Parser.Kinds
32+import Language.PureScript.Names
3233import Language.PureScript.CodeGen.JS.AST
3334
3435parseDataDeclaration :: P.Parsec String ParseState Declaration
@@ -55,6 +56,7 @@ parseTypeSynonymDeclaration =
5556parseValueDeclaration :: P.Parsec String ParseState Declaration
5657parseValueDeclaration =
5758 ValueDeclaration <$> parseIdent
59+ <*> pure Value
5860 <*> P.many parseBinderNoParens
5961 <*> P.optionMaybe parseGuard
6062 <*> (lexeme (indented *> P.char '=') *> parseValue)
src/Language/PureScript/Pretty/Types.hs+28−12
@@ -20,7 +20,7 @@ module Language.PureScript.Pretty.Types (
2020
2121import Data.Maybe (fromMaybe)
2222import Data.List (intercalate)
23−import Data.Generics (mkT, everywhere)
23+import Data.Generics (mkT, everywhere, everywhere')
2424
2525import Control.Arrow ((<+>))
2626import Control.PatternArrows
@@ -39,9 +39,9 @@ typeLiterals = mkPattern match
3939 match (TypeConstructor ctor) = Just $ show ctor
4040 match (TUnknown (Unknown u)) = Just $ 'u' : show u
4141 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
43− match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintType args) ++ ">"
44− match (ForAll ident ty _) = Just $ "forall " ++ ident ++ ". " ++ 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 prettyPrintTypeAtom args) ++ ">"
44+ match (PrettyPrintForAll idents ty) = Just $ "forall " ++ unwords idents ++ ". " ++ prettyPrintType ty
4545 match REmpty = Just "()"
4646 match row@RCons{} = Just $ '(' : prettyPrintRow row ++ ")"
4747 match _ = Nothing
@@ -77,23 +77,39 @@ appliedFunction = mkPattern match
7777 match _ = Nothing
7878
7979insertPlaceholders :: Type -> Type
80−insertPlaceholders = everywhere (mkT convert)
80+insertPlaceholders = everywhere' (mkT convertForAlls) . everywhere (mkT convert)
8181 where
8282 convert (TypeApp (TypeApp f arg) ret) | f == tyFunction = PrettyPrintFunction arg ret
8383 convert (TypeApp a el) | a == tyArray = PrettyPrintArray el
8484 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
8590
86−-- |
87−-- Generate a pretty-printed string representing a Type
88−--
89−prettyPrintType :: Type -> String
90−prettyPrintType = fromMaybe (error "Incomplete pattern") . pattern matchType () . insertPlaceholders
91+matchTypeAtom :: Pattern () Type String
92+matchTypeAtom = typeLiterals <+> fmap parens matchType
93+
94+matchType :: Pattern () Type String
95+matchType = buildPrettyPrinter operators matchTypeAtom
9196 where
92− matchType :: Pattern () Type String
93− matchType = buildPrettyPrinter operators (typeLiterals <+> fmap parens matchType)
9497 operators :: OperatorTable () Type String
9598 operators =
9699 OperatorTable [ [ AssocL typeApp $ \f x -> f ++ " " ++ x ]
97100 , [ AssocR appliedFunction $ \arg ret -> arg ++ " -> " ++ ret
98101 ]
99102 ]
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]
7272collapseBindingGroups = concatMap go
7373 where
7474 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
7676 go other = [other]
7777
7878usedIdents :: (Data d) => ModuleName -> d -> [Ident]
@@ -91,7 +91,7 @@ usedProperNames moduleName = nub . everything (++) (mkQ [] names)
9191 names _ = []
9292
9393getIdent :: Declaration -> Ident
94−getIdent (ValueDeclaration ident _ _ _) = ident
94+getIdent (ValueDeclaration ident _ _ _ _) = ident
9595getIdent _ = error "Expected ValueDeclaration"
9696
9797getProperName :: Declaration -> ProperName
@@ -115,7 +115,7 @@ toDataBindingGroup (CyclicSCC ds')
115115 isTypeSynonym TypeSynonymDeclaration{} = True
116116 isTypeSynonym _ = False
117117
118−fromValueDecl :: Declaration -> (Ident, Value)
119−fromValueDecl (ValueDeclaration ident [] Nothing val) = (ident, val)
118+fromValueDecl :: Declaration -> (Ident, NameKind, Value)
119+fromValueDecl (ValueDeclaration ident nameKind [] Nothing val) = (ident, nameKind, val)
120120fromValueDecl ValueDeclaration{} = error "Binders should have been desugared"
121121fromValueDecl _ = error "Expected ValueDeclaration"
src/Language/PureScript/Sugar/CaseDeclarations.hs+5−5
@@ -60,12 +60,12 @@ desugarCases = desugarRest <=< fmap join . mapM toDecls . groupBy inSameGroup
6060 desugarRest [] = pure []
6161
6262inSameGroup :: Declaration -> Declaration -> Bool
63−inSameGroup (ValueDeclaration ident1 _ _ _) (ValueDeclaration ident2 _ _ _) = ident1 == ident2
63+inSameGroup (ValueDeclaration ident1 _ _ _ _) (ValueDeclaration ident2 _ _ _ _) = ident1 == ident2
6464inSameGroup _ _ = False
6565
6666toDecls :: [Declaration] -> Either String [Declaration]
67−toDecls d@[ValueDeclaration _ [] Nothing _] = return d
68−toDecls ds@(ValueDeclaration ident bs _ _ : _) = do
67+toDecls d@[ValueDeclaration _ _ [] Nothing _] = return d
68+toDecls ds@(ValueDeclaration ident _ bs _ _ : _) = do
6969 let tuples = map toTuple ds
7070 unless (all ((== length bs) . length . fst) tuples) $
7171 throwError $ "Argument list lengths differ in declaration " ++ show ident
@@ -73,7 +73,7 @@ toDecls ds@(ValueDeclaration ident bs _ _ : _) = do
7373toDecls ds = return ds
7474
7575toTuple :: Declaration -> ([Binder], (Maybe Guard, Value))
76−toTuple (ValueDeclaration _ bs g val) = (bs, (g, val))
76+toTuple (ValueDeclaration _ _ bs g val) = (bs, (g, val))
7777toTuple _ = error "Not a value declaration"
7878
7979makeCaseDeclaration :: Ident -> [([Binder], (Maybe Guard, Value))] -> Declaration
@@ -85,5 +85,5 @@ makeCaseDeclaration ident alternatives =
8585 binders = [ CaseAlternative bs g val | (bs, (g, val)) <- alternatives ]
8686 value = foldr (\arg ret -> Abs (Left arg) ret) (Case vars binders) args
8787 in
88− ValueDeclaration ident [] Nothing value
88+ ValueDeclaration ident Value [] Nothing value
8989
src/Language/PureScript/Sugar/Names.hs+4−4
@@ -170,8 +170,8 @@ renameInModule imports exports (Module mn decls exps) =
170170 updateDecl d = return d
171171
172172 updateVars :: Declaration -> Either String Declaration
173− updateVars (ValueDeclaration name [] Nothing val) =
174− ValueDeclaration name [] Nothing <$> everywhereWithContextM' [] (mkS bindFunctionArgs `extS` bindBinders) val
173+ updateVars (ValueDeclaration name nameKind [] Nothing val) =
174+ ValueDeclaration name nameKind [] Nothing <$> everywhereWithContextM' [] (mkS bindFunctionArgs `extS` bindBinders) val
175175 where
176176 bindFunctionArgs bound (Abs (Left arg) val') = return (arg : bound, Abs (Left arg) val')
177177 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) =
179179 bindFunctionArgs bound other = return (bound, other)
180180 bindBinders :: [Ident] -> CaseAlternative -> Either String ([Ident], CaseAlternative)
181181 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
183183 updateVars other = return other
184184 updateValue (Constructor name) = Constructor <$> updateDataConstructorName name
185185 updateValue v = return v
@@ -252,7 +252,7 @@ findExports = foldM addModule $ M.singleton (ModuleName [ProperName "Prim"]) pri
252252 addDecl mn env (DataDeclaration tn _ dcs) = addType env mn tn (map fst dcs)
253253 addDecl mn env (TypeSynonymDeclaration tn _ _) = addType env mn tn []
254254 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
256256 addDecl mn env (ExternDeclaration _ name _ _) = addValue env mn name
257257 addDecl _ env _ = return env
258258
src/Language/PureScript/Sugar/TypeClasses.hs+4−4
@@ -122,7 +122,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
122122 let memberTypes = map (second (replaceAllTypeVars (zip args tys))) instanceTys
123123 let entryName = Escaped (show name)
124124 memberNames <- mapM (memberToNameAndValue memberTypes) decls
125− return $ ValueDeclaration entryName [] Nothing
125+ return $ ValueDeclaration entryName TypeInstanceDictionaryValue [] Nothing
126126 (TypedValue True
127127 (foldr (Abs . (\n -> Left . Ident $ '_' : show n)) (ObjectLiteral memberNames) [1..max 1 (length deps)])
128128 (quantify (if null deps then
@@ -132,7 +132,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
132132 )
133133 where
134134 memberToNameAndValue :: [(String, Type)] -> Declaration -> Desugar (String, Value)
135− memberToNameAndValue tys' (ValueDeclaration ident _ _ _) = do
135+ memberToNameAndValue tys' (ValueDeclaration ident _ _ _ _) = do
136136 memberType <- lift . maybe (Left "Type class member type not found") Right $ lookup (identToJs ident) tys'
137137 memberName <- mkDictionaryEntryName name ident
138138 return (identToJs ident, TypedValue False
@@ -141,13 +141,13 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls = do
141141 memberToNameAndValue _ _ = error "Invalid declaration in type instance definition"
142142
143143typeInstanceDictionaryEntryDeclaration :: 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
145145 m <- get
146146 valTy <- lift $ do (args, members) <- lookupTypeClass m
147147 ty' <- lookupIdent members
148148 return $ replaceAllTypeVars (zip args tys) ty'
149149 entryName <- mkDictionaryEntryName name ident
150− return $ ValueDeclaration entryName [] Nothing
150+ return $ ValueDeclaration entryName TypeInstanceMember [] Nothing
151151 (TypedValue True val (quantify (if null deps then valTy else ConstrainedType deps valTy)))
152152 where
153153 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
3636-- Replace all top level type declarations with type annotations
3737--
3838desugarTypeDeclarations :: [Declaration] -> Either String [Declaration]
39−desugarTypeDeclarations (TypeDeclaration name ty : ValueDeclaration name' [] Nothing val : rest) | name == name' =
40− desugarTypeDeclarations (ValueDeclaration name [] Nothing (TypedValue True val ty) : rest)
39+desugarTypeDeclarations (TypeDeclaration name ty : ValueDeclaration name' nameKind [] Nothing val : rest) | name == name' =
40+ desugarTypeDeclarations (ValueDeclaration name nameKind [] Nothing (TypedValue True val ty) : rest)
4141desugarTypeDeclarations (TypeDeclaration name _ : _) = throwError $ "Orphan type declaration for " ++ show name
4242desugarTypeDeclarations (d:ds) = (:) d <$> desugarTypeDeclarations ds
4343desugarTypeDeclarations [] = return []
src/Language/PureScript/TypeChecker.hs+13−13
@@ -51,7 +51,7 @@ addDataConstructor moduleName name args dctor tys = do
5151 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
5252 let dctorTy = foldr function retTy tys
5353 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) }
5555
5656addTypeSynonym :: ModuleName -> ProperName -> [String] -> Type -> Kind -> Check ()
5757addTypeSynonym moduleName name args ty kind = do
@@ -66,10 +66,10 @@ valueIsNotDefined moduleName name = do
6666 Just _ -> throwError $ show name ++ " is already defined"
6767 Nothing -> return ()
6868
69−addValue :: ModuleName -> Ident -> Type -> Check ()
70−addValue moduleName name ty = do
69+addValue :: ModuleName -> Ident -> Type -> NameKind -> Check ()
70+addValue moduleName name ty nameKind = do
7171 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) })
7373
7474addTypeClassDictionaries :: [TypeClassDictionaryInScope] -> Check ()
7575addTypeClassDictionaries entries =
@@ -128,23 +128,23 @@ typeCheckAll mainModuleName moduleName (d@(TypeSynonymDeclaration name args ty)
128128 ds <- typeCheckAll mainModuleName moduleName rest
129129 return $ d : ds
130130typeCheckAll _ _ (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
132132 d <- rethrow (("Error in declaration " ++ show name ++ ":\n") ++) $ do
133133 valueIsNotDefined moduleName name
134134 [(_, (val', ty))] <- typesOf mainModuleName moduleName [(name, val)]
135− addValue moduleName name ty
136− return $ ValueDeclaration name [] Nothing val'
135+ addValue moduleName name ty nameKind
136+ return $ ValueDeclaration name nameKind [] Nothing val'
137137 ds <- typeCheckAll mainModuleName moduleName rest
138138 return $ d : ds
139139typeCheckAll _ _ (ValueDeclaration{} : _) = error "Binders were not desugared"
140140typeCheckAll mainModuleName moduleName (BindingGroupDeclaration vals : rest) = do
141− d <- rethrow (("Error in binding group " ++ show (map fst vals) ++ ":\n") ++) $ do
142− forM_ (map fst vals) $ \name ->
141+ d <- rethrow (("Error in binding group " ++ show (map (\(ident, _, _) -> ident) vals) ++ ":\n") ++) $ do
142+ forM_ (map (\(ident, _, _) -> ident) vals) $ \name ->
143143 valueIsNotDefined moduleName name
144− tys <- typesOf mainModuleName moduleName vals
145− vals' <- forM (zip (map fst vals) (map snd tys)) $ \(name, (val, ty)) -> do
146− addValue moduleName name ty
147− return (name, val)
144+ tys <- typesOf mainModuleName moduleName $ map (\(ident, _, ty) -> (ident, ty)) vals
145+ vals' <- forM (zipWith (\(name, nameKind, _) (_, (val, ty)) -> (name, val, nameKind, ty)) vals tys) $ \(name, val, nameKind, ty) -> do
146+ addValue moduleName name ty nameKind
147+ return (name, nameKind, val)
148148 return $ BindingGroupDeclaration vals'
149149 ds <- typeCheckAll mainModuleName moduleName rest
150150 return $ d : ds
src/Language/PureScript/TypeChecker/Kinds.hs+1−1
@@ -74,7 +74,7 @@ kindsOf moduleName name args ts = fmap tidyUp . liftUnify $ do
7474 bindLocalTypeVariables moduleName dict $
7575 solveTypes ts kargs tyCon
7676 where
77− tidyUp (k, sub) = sub $? k
77+ tidyUp (k, sub) = starIfUnknown $ sub $? k
7878
7979-- |
8080-- 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
2222import Language.PureScript.Kinds
2323import Language.PureScript.Values
2424import Language.PureScript.Names
25−import Language.PureScript.Declarations
2625import Language.PureScript.Prim
2726
2827import Data.Maybe
@@ -35,27 +34,6 @@ import Control.Arrow (first)
3534
3635import qualified Data.Map as M
3736
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−
5937-- |
6038-- The @Environment@ defines all values and types which are currently in scope:
6139--
@@ -71,7 +49,7 @@ data Environment = Environment {
7149 -- |
7250 -- Data constructors currently in scope, along with their associated data type constructors
7351 --
74− , dataConstructors :: M.Map (Qualified ProperName) Type
52+ , dataConstructors :: M.Map (Qualified ProperName) (ProperName, Type)
7553 -- |
7654 -- Type synonyms currently in scope
7755 --
src/Language/PureScript/TypeChecker/Types.hs+4−4
@@ -533,8 +533,8 @@ infer' v@(Constructor c) = do
533533 env <- getEnv
534534 case M.lookup c (dataConstructors env) of
535535 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
536− Just ty -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
537− return $ TypedValue True v ty'
536+ Just (_, ty) -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
537+ return $ TypedValue True v ty'
538538infer' (Case vals binders) = do
539539 ts <- mapM infer vals
540540 ret <- fresh
@@ -582,7 +582,7 @@ inferBinder val (VarBinder name) = return $ M.singleton name val
582582inferBinder val (ConstructorBinder ctor binders) = do
583583 env <- getEnv
584584 case M.lookup ctor (dataConstructors env) of
585− Just ty -> do
585+ Just (_, ty) -> do
586586 (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contains constraints") ty
587587 go binders fn
588588 where
@@ -778,7 +778,7 @@ check' (Constructor c) ty = do
778778 env <- getEnv
779779 case M.lookup c (dataConstructors env) of
780780 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
781− Just ty1 -> do
781+ Just (_, ty1) -> do
782782 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
783783 _ <- subsumes Nothing repl ty
784784 return $ TypedValue True (Constructor c) ty
src/Language/PureScript/Types.hs+5−1
@@ -86,7 +86,11 @@ data Type
8686 -- |
8787 -- A placeholder used in pretty printing
8888 --
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)
9094
9195-- |
9296-- Convert a row to a list of pairs of labels and types