git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' of https://github.com/garyb/purescript
a621359Gary Burgess
docgen/Main.hsnew file+155
@@ -0,0 +1,155 @@
1+-----------------------------------------------------------------------------
2+--
3+-- Module : Main
4+-- Copyright : (c) Phil Freeman 2013
5+-- License : MIT
6+--
7+-- Maintainer : Phil Freeman <paf31@cantab.net>
8+-- Stability : experimental
9+-- Portability :
10+--
11+-- |
12+--
13+-----------------------------------------------------------------------------
14+
15+module Main where
16+
17+import qualified Language.PureScript as P
18+import System.Console.CmdTheLine
19+import Control.Applicative
20+import Control.Monad
21+import Control.Monad.Writer
22+import System.Exit (exitSuccess, exitFailure)
23+import qualified System.IO.UTF8 as U
24+import qualified Paths_purescript as Paths
25+import Data.Version (showVersion)
26+import Data.List
27+import Data.Function (on)
28+
29+docgen :: FilePath -> IO ()
30+docgen input = do
31+ text <- U.readFile input
32+ case P.runIndentParser input P.parseModules text of
33+ Left err -> do
34+ U.print err
35+ exitFailure
36+ Right ms -> do
37+ U.putStrLn . runDocs $ renderModules ms
38+ exitSuccess
39+
40+type Docs = Writer [String] ()
41+
42+runDocs :: Docs -> String
43+runDocs = unlines . execWriter
44+
45+spacer :: Docs
46+spacer = tell [""]
47+
48+headerLevel :: Int -> String -> Docs
49+headerLevel level hdr = tell [replicate level '#' ++ ' ' : hdr]
50+
51+atIndent :: Int -> String -> Docs
52+atIndent indent text =
53+ let ls = lines text in
54+ forM_ ls $ \l -> tell [replicate indent ' ' ++ l]
55+
56+renderModules :: [P.Module] -> Docs
57+renderModules ms = do
58+ headerLevel 1 "Module Documentation"
59+ mapM_ renderModule ms
60+
61+renderModule :: P.Module -> Docs
62+renderModule (P.Module (P.ProperName moduleName) ds) = do
63+ headerLevel 2 $ "Module " ++ moduleName
64+ spacer
65+ headerLevel 3 "Types"
66+ spacer
67+ renderTopLevel (filter isTypeDeclaration ds)
68+ spacer
69+ headerLevel 3 "Type Classes"
70+ spacer
71+ renderTopLevel (filter isTypeClassDeclaration ds)
72+ spacer
73+ headerLevel 3 "Type Class Instances"
74+ spacer
75+ renderTopLevel (filter isTypeInstanceDeclaration ds)
76+ spacer
77+ headerLevel 3 "Values"
78+ spacer
79+ renderTopLevel (filter isValueDeclaration ds)
80+ spacer
81+
82+renderTopLevel :: [P.Declaration] -> Docs
83+renderTopLevel decls = forM_ (sortBy (compare `on` getName) decls) $ \decl -> do
84+ renderDeclaration 4 decl
85+ spacer
86+
87+renderDeclaration :: Int -> P.Declaration -> Docs
88+renderDeclaration n (P.TypeDeclaration ident ty) =
89+ atIndent n $ show ident ++ " :: " ++ P.prettyPrintType ty
90+renderDeclaration n (P.ExternDeclaration _ ident _ ty) =
91+ atIndent n $ show ident ++ " :: " ++ P.prettyPrintType ty
92+renderDeclaration n (P.DataDeclaration name args ctors) = do
93+ let typeName = P.runProperName name ++ " " ++ intercalate " " args
94+ atIndent n $ "data " ++ typeName ++ " where"
95+ forM_ ctors $ \(ctor, ty) -> do
96+ atIndent (n + 2) $ P.runProperName ctor ++ " :: " ++ maybe "" ((++ " -> ") . P.prettyPrintType) ty ++ typeName
97+renderDeclaration n (P.ExternDataDeclaration name kind) =
98+ atIndent n $ "data " ++ P.runProperName name ++ " :: " ++ P.prettyPrintKind kind
99+renderDeclaration n (P.TypeSynonymDeclaration name args ty) = do
100+ let typeName = P.runProperName name ++ " " ++ intercalate " " args
101+ atIndent n $ "type " ++ typeName ++ " = " ++ P.prettyPrintType ty
102+renderDeclaration n (P.TypeClassDeclaration name arg ds) = do
103+ atIndent n $ "class " ++ P.runProperName name ++ " " ++ arg ++ " where"
104+ mapM_ (renderDeclaration (n + 2)) ds
105+renderDeclaration n (P.TypeInstanceDeclaration constraints name ty _) = do
106+ let constraintsText = case constraints of
107+ [] -> ""
108+ cs -> "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ P.prettyPrintType ty' ++ ")") cs) ++ ") => "
109+ atIndent n $ constraintsText ++ "instance " ++ show name ++ " " ++ P.prettyPrintType ty
110+renderDeclaration _ _ = return ()
111+
112+getName :: P.Declaration -> String
113+getName (P.TypeDeclaration ident _) = show ident
114+getName (P.ExternDeclaration _ ident _ _) = show ident
115+getName (P.DataDeclaration name _ _) = P.runProperName name
116+getName (P.ExternDataDeclaration name _) = P.runProperName name
117+getName (P.TypeSynonymDeclaration name _ _) = P.runProperName name
118+getName (P.TypeClassDeclaration name _ _) = P.runProperName name
119+getName (P.TypeInstanceDeclaration _ name _ _) = show name
120+getName _ = error "Invalid argument to getName"
121+
122+isValueDeclaration :: P.Declaration -> Bool
123+isValueDeclaration (P.TypeDeclaration _ _) = True
124+isValueDeclaration (P.ExternDeclaration _ _ _ _) = True
125+isValueDeclaration _ = False
126+
127+isTypeDeclaration :: P.Declaration -> Bool
128+isTypeDeclaration (P.DataDeclaration _ _ _) = True
129+isTypeDeclaration (P.ExternDataDeclaration _ _) = True
130+isTypeDeclaration (P.TypeSynonymDeclaration _ _ _) = True
131+isTypeDeclaration _ = False
132+
133+isTypeClassDeclaration :: P.Declaration -> Bool
134+isTypeClassDeclaration (P.TypeClassDeclaration _ _ _) = True
135+isTypeClassDeclaration _ = False
136+
137+isTypeInstanceDeclaration :: P.Declaration -> Bool
138+isTypeInstanceDeclaration (P.TypeInstanceDeclaration _ _ _ _) = True
139+isTypeInstanceDeclaration _ = False
140+
141+inputFile :: Term FilePath
142+inputFile = value $ pos 0 "input.ps" $ posInfo { posDoc = "The input .ps file" }
143+
144+term :: Term (IO ())
145+term = docgen <$> inputFile
146+
147+termInfo :: TermInfo
148+termInfo = defTI
149+ { termName = "docgen"
150+ , version = showVersion $ Paths.version
151+ , termDoc = "Generate Markdown documentation from PureScript extern files"
152+ }
153+
154+main :: IO ()
155+main = run (term, termInfo)
docs/source/blocks.rst+1−1
@@ -73,7 +73,7 @@ While loops repeat a set of statements while a boolean expression evaluates to `
73If-Then-Else Statements
73If-Then-Else Statements
74-----------------------
74-----------------------
75
75
76−Else branches are optional, and may contain further ``if`` statements, just as in Javascript:
76+Else branches are optional, and may contain further ``if`` statements, just as in Javascript::
77
77
78 collatz n = {
78 collatz n = {
79 var count = 0;
79 var count = 0;
docs/source/prelude.rst+745−60
@@ -1,88 +1,773 @@
1−Prelude
1+Module Documentation
2−=======
2+====================
3
3
4−The Prelude is a collection of standard modules which define types for standard Javascript functions, as well as some common functions that will be familiar to users of Haskell or similar functional languages.
5−
6−Prelude Module
4+Module Prelude
7--------------
5--------------
8
6
9−=========== ============================================================ ===========================================
7+Types
10−Name Type Description
8+~~~~~
11−=========== ============================================================ ===========================================
9+
10+::
11+
12+ data Array :: * -> *
13+
14+ data Boolean :: *
15+
16+ data Function :: * -> * -> *
17+
18+ data Number :: *
19+
20+ data Ref a where
21+ Ref :: a -> Ref a
22+
23+ data String :: *
24+
25+Type Classes
26+~~~~~~~~~~~~
27+
28+::
29+
30+ class Alternative f where
31+ empty :: forall a. f a
32+ (<|>) :: forall a. f a -> f a -> f a
33+
34+ class Applicative f where
35+ pure :: forall a. a -> f a
36+ (<*>) :: forall b. forall a. f (a -> b) -> f a -> f b
37+
38+ class Bits b where
39+ (&) :: b -> b -> b
40+ (|) :: b -> b -> b
41+ (^) :: b -> b -> b
42+ shl :: b -> Prelude.Number -> b
43+ shr :: b -> Prelude.Number -> b
44+ zshr :: b -> Prelude.Number -> b
45+ complement :: b -> b
46+
47+ class BoolLike b where
48+ (&&) :: b -> b -> b
49+ (||) :: b -> b -> b
50+ not :: b -> b
51+
52+ class Category a where
12−``id`` ``forall a. a -> a`` Identity function
53+ id :: forall t. a t t
13−``flip`` ``forall a b c. (a -> b -> c) -> b -> a -> c`` Flips the order of a function's arguments
54+ (<<<) :: forall d. forall c. forall b. a c d -> a b c -> a b d
55+ (>>>) :: forall d. forall c. forall b. a b c -> a c d -> a b d
56+
57+ class Eq a where
58+ (==) :: a -> a -> Prelude.Boolean
59+ (/=) :: a -> a -> Prelude.Boolean
60+
61+ class Functor f where
62+ (<$>) :: forall b. forall a. Prelude.Function a b -> f a -> f b
63+
64+ class Monad m where
65+ ret :: forall a. a -> m a
66+ (>>=) :: forall b. forall a. m a -> Prelude.Function a (m b) -> m b
67+
68+ class Num a where
69+ (+) :: a -> a -> a
70+ (-) :: a -> a -> a
71+ (*) :: a -> a -> a
72+ (/) :: a -> a -> a
73+ (%) :: a -> a -> a
74+ negate :: a -> a
75+
76+ class Ord a where
77+ (<) :: a -> a -> Prelude.Boolean
78+ (>) :: a -> a -> Prelude.Boolean
79+ (<=) :: a -> a -> Prelude.Boolean
80+ (>=) :: a -> a -> Prelude.Boolean
81+
82+ class Read a where
83+ read :: Prelude.String -> a
84+
85+ class Show a where
86+ show :: a -> Prelude.String
87+
88+Type Class Instances
89+~~~~~~~~~~~~~~~~~~~~
90+
91+::
92+
93+ (Monad (m)) => instance Applicative m
94+
95+ instance Bits Prelude.Number
96+
97+ instance BoolLike Prelude.Boolean
98+
99+ instance Category Prelude.Function
100+
101+ instance Eq Ref a
102+
103+ instance Eq Prelude.String
104+
105+ instance Eq Prelude.Number
106+
107+ instance Eq Prelude.Boolean
108+
109+ (Eq (a)) => instance Eq Prelude.Array a
110+
111+ (Applicative (f)) => instance Functor f
112+
113+ instance Num Prelude.Number
114+
115+ instance Ord Prelude.Number
116+
117+ instance Prelude.Show Prelude.Number
118+
119+ instance Read Prelude.String
120+
121+ instance Read Prelude.Boolean
122+
123+ instance Show Prelude.String
124+
125+ instance Show Prelude.Boolean
126+
127+Values
128+~~~~~~
129+
130+::
131+
132+ (!!) :: forall a. Prelude.Array a -> Prelude.Number -> a
133+
134+ (#) :: forall b. forall a. a -> Prelude.Function a b -> b
135+
136+ ($) :: forall b. forall a. Prelude.Function a b -> a -> b
137+
138+ (++) :: Prelude.String -> Prelude.String -> Prelude.String
139+
140+ boolAnd :: Prelude.Boolean -> Prelude.Boolean -> Prelude.Boolean
141+
142+ boolNot :: Prelude.Boolean -> Prelude.Boolean
143+
144+ boolOr :: Prelude.Boolean -> Prelude.Boolean -> Prelude.Boolean
145+
146+ flip :: forall c. forall b. forall a. Prelude.Function a (b -> c) -> b -> a -> c
147+
14−``konst`` ``forall a b. a -> b -> a`` Defines a constant function
148+ konst :: forall b. forall a. a -> b -> a
15−``(<|)`` ``forall a b c. (a -> b) -> (b -> c) -> a -> c`` Function composition
149+
16−``(|>)`` ``forall a b c. (b -> c) -> (a -> b) -> a -> c`` Function composition
150+ numAdd :: Prelude.Number -> Prelude.Number -> Prelude.Number
17−``($)`` ``forall a b. (a -> b) -> a -> b`` Function application
151+
18−=========== ============================================================ ===========================================
152+ numAnd :: Prelude.Number -> Prelude.Number -> Prelude.Number
19−
153+
20−======= ===========================================
154+ numComplement :: Prelude.Number -> Prelude.Number
21−Name Description
155+
22−======= ===========================================
156+ numDiv :: Prelude.Number -> Prelude.Number -> Prelude.Number
23−Show Type class for types whose values can be
157+
24− converted to strings
158+ numGreater :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
25−Monad Type class for type constructors which
159+
26− support ``do`` notation
160+ numGreaterEq :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
27−======= ===========================================
161+
28−
162+ numLess :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
163+
164+ numLessEq :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
165+
166+ numMod :: Prelude.Number -> Prelude.Number -> Prelude.Number
167+
168+ numMul :: Prelude.Number -> Prelude.Number -> Prelude.Number
169+
170+ numNegate :: Prelude.Number -> Prelude.Number
171+
172+ numOr :: Prelude.Number -> Prelude.Number -> Prelude.Number
173+
174+ numShl :: Prelude.Number -> Prelude.Number -> Prelude.Number
175+
176+ numShr :: Prelude.Number -> Prelude.Number -> Prelude.Number
177+
178+ numSub :: Prelude.Number -> Prelude.Number -> Prelude.Number
179+
180+ numXor :: Prelude.Number -> Prelude.Number -> Prelude.Number
181+
182+ numZshr :: Prelude.Number -> Prelude.Number -> Prelude.Number
183+
184+ refEq :: forall a. Ref a -> Ref a -> Prelude.Boolean
185+
186+ refIneq :: forall a. Ref a -> Ref a -> Prelude.Boolean
187+
188+ showNumber :: Prelude.Number -> Prelude.String
189+
190+ unsafeRefEq :: forall a. a -> a -> Prelude.Boolean
191+
192+ unsafeRefIneq :: forall a. a -> a -> Prelude.Boolean
193+
29−String Module
194+Module Monoid
30-------------
195-------------
31
196
32−`TODO`
197+Types
198+~~~~~
199+
200+Type Classes
201+~~~~~~~~~~~~
202+
203+::
204+
205+ class Monoid m where
206+ mempty :: m
207+ (<>) :: m -> m -> m
208+
209+Type Class Instances
210+~~~~~~~~~~~~~~~~~~~~
33
211
212+::
213+
214+ instance Monoid Prelude.String
215+
216+Values
217+~~~~~~
218+
219+::
220+
221+ mconcat :: forall m. (Monoid (m)) => Prelude.Array m -> m
222+
34−Regex Module
223+Module Monad
35------------
224------------
36
225
37−`TODO`
226+Types
227+~~~~~
228+
229+Type Classes
230+~~~~~~~~~~~~
231+
232+Type Class Instances
233+~~~~~~~~~~~~~~~~~~~~
234+
235+Values
236+~~~~~~
237+
238+::
239+
240+ (<=<) :: forall c. forall b. forall a. forall m. (Monad (m)) => Prelude.Function b (m c) -> Prelude.Function a (m b) -> a -> m c
38
241
242+ (>=>) :: forall c. forall b. forall a. forall m. (Monad (m)) => Prelude.Function a (m b) -> Prelude.Function b (m c) -> a -> m c
243+
244+ foldM :: forall b. forall a. forall m. (Monad (m)) => Prelude.Function a (b -> m a) -> a -> Prelude.Array b -> m a
245+
246+ join :: forall a. forall m. (Monad (m)) => m (m a) -> m a
247+
248+ mapM :: forall b. forall a. forall m. (Monad (m)) => Prelude.Function a (m b) -> Prelude.Array a -> m [b]
249+
250+ replicateM :: forall a. forall m. (Monad (m)) => Prelude.Number -> m a -> m [a]
251+
252+ sequence :: forall a. forall m. (Monad (m)) => Prelude.Array (m a) -> m [a]
253+
254+ when :: forall m. (Monad (m)) => Prelude.Boolean -> m { } -> m { }
255+
39−Maybe Module
256+Module Maybe
40------------
257------------
41
258
42−`TODO`
259+Types
260+~~~~~
261+
262+::
263+
264+ data Maybe a where
265+ Nothing :: Maybe a
266+ Just :: a -> Maybe a
267+
268+Type Classes
269+~~~~~~~~~~~~
43
270
271+Type Class Instances
272+~~~~~~~~~~~~~~~~~~~~
273+
274+::
275+
276+ instance Prelude.Monad Maybe
277+
278+Values
279+~~~~~~
280+
281+::
282+
283+ fromMaybe :: forall a. a -> Maybe a -> a
284+
285+ maybe :: forall b. forall a. b -> Prelude.Function a b -> Maybe a -> b
286+
44−Either Module
287+Module Either
45-------------
288-------------
46
289
47−`TODO`
290+Types
48−
291+~~~~~
292+
293+::
294+
295+ data Either a b where
296+ Left :: a -> Either a b
297+ Right :: b -> Either a b
298+
299+Type Classes
300+~~~~~~~~~~~~
301+
302+Type Class Instances
303+~~~~~~~~~~~~~~~~~~~~
304+
305+::
306+
307+ instance Prelude.Monad Either e
308+
309+Values
310+~~~~~~
311+
312+::
313+
314+ either :: forall c. forall b. forall a. Prelude.Function a c -> Prelude.Function b c -> Either a b -> c
315+
49−Arrays Module
316+Module Arrays
50-------------
317-------------
51
318
52−`TODO`
319+Types
53−
320+~~~~~
321+
322+Type Classes
323+~~~~~~~~~~~~
324+
325+Type Class Instances
326+~~~~~~~~~~~~~~~~~~~~
327+
328+::
329+
330+ instance Prelude.Alternative Prelude.Array
331+
332+ instance Prelude.Monad Prelude.Array
333+
334+ (Prelude.Show (a)) => instance Prelude.Show Prelude.Array a
335+
336+Values
337+~~~~~~
338+
339+::
340+
341+ (:) :: forall a. a -> Prelude.Array a -> Prelude.Array a
342+
343+ all :: forall a. Prelude.Function a Prelude.Boolean -> Prelude.Array a -> Prelude.Boolean
344+
345+ any :: forall a. Prelude.Function a Prelude.Boolean -> Prelude.Array a -> Prelude.Boolean
346+
347+ concat :: forall a. Prelude.Array a -> Prelude.Array a -> Prelude.Array a
348+
349+ concatMap :: forall b. forall a. Prelude.Array a -> Prelude.Function a [b] -> Prelude.Array b
350+
351+ filter :: forall a. Prelude.Function a Prelude.Boolean -> Prelude.Array a -> Prelude.Array a
352+
353+ foldl :: forall b. forall a. Prelude.Function a (b -> b) -> b -> Prelude.Array a -> b
354+
355+ foldr :: forall b. forall a. Prelude.Function a (b -> a) -> a -> Prelude.Array b -> a
356+
357+ head :: forall a. Prelude.Array a -> a
358+
359+ headSafe :: forall a. Prelude.Array a -> Maybe a
360+
361+ indexOf :: forall a. Prelude.Array a -> a -> Prelude.Number
362+
363+ isEmpty :: forall a. Prelude.Array a -> Prelude.Boolean
364+
365+ joinS :: Prelude.Array Prelude.String -> Prelude.String
366+
367+ joinWith :: Prelude.Array Prelude.String -> Prelude.String -> Prelude.String
368+
369+ lastIndexOf :: forall a. Prelude.Array a -> a -> Prelude.Number
370+
371+ length :: forall a. Prelude.Array a -> Prelude.Number
372+
373+ map :: forall b. forall a. Prelude.Function a b -> Prelude.Array a -> Prelude.Array b
374+
375+ push :: forall a. Prelude.Array a -> a -> Prelude.Array a
376+
377+ range :: Prelude.Number -> Prelude.Number -> Prelude.Array Prelude.Number
378+
379+ reverse :: forall a. Prelude.Array a -> Prelude.Array a
380+
381+ shift :: forall a. Prelude.Array a -> Prelude.Array a
382+
383+ singleton :: forall a. a -> Prelude.Array a
384+
385+ slice :: forall a. Prelude.Number -> Prelude.Number -> Prelude.Array a -> Prelude.Array a
386+
387+ sort :: forall a. Prelude.Array a -> Prelude.Array a
388+
389+ splice :: forall a. Prelude.Number -> Prelude.Number -> Prelude.Array a -> Prelude.Array a -> Prelude.Array a
390+
391+ tail :: forall a. Prelude.Array a -> Prelude.Array a
392+
393+ tailSafe :: forall a. Prelude.Array a -> Maybe [a]
394+
395+ zipWith :: forall c. forall b. forall a. Prelude.Function a (b -> c) -> Prelude.Array a -> Prelude.Array b -> Prelude.Array c
396+
54−Tuple Module
397+Module Tuple
55------------
398------------
56
399
57−`TODO`
400+Types
58−
401+~~~~~
59−Eff Module
402+
60−----------
403+::
404+
405+ type Tuple a b = { snd :: b, fst :: a }
406+
407+Type Classes
408+~~~~~~~~~~~~
61
409
62−`TODO`
410+Type Class Instances
63−
411+~~~~~~~~~~~~~~~~~~~~
412+
413+Values
414+~~~~~~
415+
416+::
417+
418+ curry :: forall c. forall b. forall a. Prelude.Function (Tuple a b) c -> a -> b -> c
419+
420+ tuple :: forall b. forall a. a -> b -> Tuple a b
421+
422+ uncurry :: forall c. forall b. forall a. Prelude.Function a (b -> c) -> Tuple a b -> c
423+
424+ unzip :: forall b. forall a. Prelude.Array (Tuple a b) -> Tuple [a] [b]
425+
426+ zip :: forall b. forall a. Prelude.Array a -> Prelude.Array b -> Prelude.Array (Tuple a b)
427+
64−Errors Module
428+Module String
65-------------
429-------------
66
430
67−`TODO`
431+Types
68−
432+~~~~~
433+
434+Type Classes
435+~~~~~~~~~~~~
436+
437+Type Class Instances
438+~~~~~~~~~~~~~~~~~~~~
439+
440+Values
441+~~~~~~
442+
443+::
444+
445+ charAt :: Prelude.Number -> Prelude.String -> Prelude.String
446+
447+ indexOfS :: Prelude.String -> Prelude.String -> Prelude.Number
448+
449+ lastIndexOfS :: Prelude.String -> Prelude.String -> Prelude.Number
450+
451+ lengthS :: Prelude.String -> Prelude.Number
452+
453+ localeCompare :: Prelude.String -> Prelude.String -> Prelude.Number
454+
455+ replace :: Prelude.String -> Prelude.String -> Prelude.String -> Prelude.String
456+
457+ sliceS :: Prelude.Number -> Prelude.Number -> Prelude.String -> Prelude.String
458+
459+ split :: Prelude.String -> Prelude.String -> Prelude.Array Prelude.String
460+
461+ substr :: Prelude.Number -> Prelude.Number -> Prelude.String -> Prelude.String
462+
463+ substring :: Prelude.Number -> Prelude.Number -> Prelude.String -> Prelude.String
464+
465+ toLower :: Prelude.String -> Prelude.String
466+
467+ toUpper :: Prelude.String -> Prelude.String
468+
469+ trim :: Prelude.String -> Prelude.String
470+
69−IORef Module
471+Module Regex
70------------
472------------
71
473
72−`TODO`
474+Types
73−
475+~~~~~
476+
477+::
478+
479+ data Regex :: *
480+
481+Type Classes
482+~~~~~~~~~~~~
483+
484+Type Class Instances
485+~~~~~~~~~~~~~~~~~~~~
486+
487+Values
488+~~~~~~
489+
490+::
491+
492+ match :: Regex -> Prelude.String -> Prelude.Array Prelude.String
493+
494+ regex :: Prelude.String -> Prelude.String -> Regex
495+
496+ replaceR :: Regex -> Prelude.String -> Prelude.String -> Prelude.String
497+
498+ search :: Regex -> Prelude.String -> Prelude.Number
499+
500+ test :: Regex -> Prelude.String -> Prelude.Boolean
501+
74−Random Module
502+Module Global
75-------------
503-------------
76
504
77−`TODO`
505+Types
78−
506+~~~~~
507+
508+Type Classes
509+~~~~~~~~~~~~
510+
511+Type Class Instances
512+~~~~~~~~~~~~~~~~~~~~
513+
514+Values
515+~~~~~~
516+
517+::
518+
519+ decodeURI :: Prelude.String -> Prelude.String
520+
521+ decodeURIComponent :: Prelude.String -> Prelude.String
522+
523+ encodeURI :: Prelude.String -> Prelude.String
524+
525+ encodeURIComponent :: Prelude.String -> Prelude.String
526+
527+ infinity :: Prelude.Number
528+
529+ isFinite :: Prelude.Number -> Prelude.Boolean
530+
531+ isNaN :: Prelude.Number -> Prelude.Boolean
532+
533+ nan :: Prelude.Number
534+
535+ parseFloat :: Prelude.String -> Prelude.Number
536+
537+ parseInt :: Prelude.String -> Prelude.Number
538+
539+ toExponential :: Prelude.Number -> Prelude.String
540+
541+ toFixed :: Prelude.Number -> Prelude.Number -> Prelude.String
542+
543+ toPrecision :: Prelude.Number -> Prelude.Number -> Prelude.String
544+
79−ST Module
545+Module Math
80−---------
546+-----------
547+
548+Types
549+~~~~~
550+
551+Type Classes
552+~~~~~~~~~~~~
553+
554+Type Class Instances
555+~~~~~~~~~~~~~~~~~~~~
556+
557+Values
558+~~~~~~
559+
560+::
561+
562+ abs :: Prelude.Number -> Prelude.Number
563+
564+ aceil :: Prelude.Number -> Prelude.Number
565+
566+ acos :: Prelude.Number -> Prelude.Number
567+
568+ asin :: Prelude.Number -> Prelude.Number
569+
570+ atan :: Prelude.Number -> Prelude.Number
571+
572+ atan2 :: Prelude.Number -> Prelude.Number -> Prelude.Number
573+
574+ cos :: Prelude.Number -> Prelude.Number
575+
576+ exp :: Prelude.Number -> Prelude.Number
577+
578+ floor :: Prelude.Number -> Prelude.Number
579+
580+ log :: Prelude.Number -> Prelude.Number
581+
582+ max :: Prelude.Number -> Prelude.Number
583+
584+ min :: Prelude.Number -> Prelude.Number
585+
586+ pow :: Prelude.Number -> Prelude.Number
587+
588+ round :: Prelude.Number -> Prelude.Number
589+
590+ sin :: Prelude.Number -> Prelude.Number
591+
592+ sqrt :: Prelude.Number -> Prelude.Number
593+
594+ tan :: Prelude.Number -> Prelude.Number
81
595
82−`TODO`
596+Module Eff
83−
597+----------
598+
599+Types
600+~~~~~
601+
602+::
603+
604+ data Eff :: # ! -> * -> *
605+
606+ type Pure a = forall e. Eff e a
607+
608+Type Classes
609+~~~~~~~~~~~~
610+
611+Type Class Instances
612+~~~~~~~~~~~~~~~~~~~~
613+
614+::
615+
616+ instance Prelude.Monad Eff e
617+
618+Values
619+~~~~~~
620+
621+::
622+
623+ bindEff :: forall b. forall a. forall e. Eff e a -> Prelude.Function a (Eff e b) -> Eff e b
624+
625+ forE :: forall e. Prelude.Number -> Prelude.Number -> Prelude.Function Prelude.Number (Eff e { }) -> Eff e { }
626+
627+ foreachE :: forall a. forall e. Prelude.Array a -> Prelude.Function a (Eff e { }) -> Eff e { }
628+
629+ retEff :: forall a. forall e. a -> Eff e a
630+
631+ runPure :: forall a. Pure a -> a
632+
633+ untilE :: forall e. Eff e Prelude.Boolean -> Eff e { }
634+
635+ whileE :: forall e. Eff e Prelude.Boolean -> Eff e { } -> Eff e { }
636+
637+Module Random
638+-------------
639+
640+Types
641+~~~~~
642+
643+::
644+
645+ data Random :: !
646+
647+Type Classes
648+~~~~~~~~~~~~
649+
650+Type Class Instances
651+~~~~~~~~~~~~~~~~~~~~
652+
653+Values
654+~~~~~~
655+
656+::
657+
658+ random :: forall e. Eff random :: Random | e Prelude.Number
659+
660+Module Errors
661+-------------
662+
663+Types
664+~~~~~
665+
666+::
667+
668+ data Error :: * -> !
669+
670+Type Classes
671+~~~~~~~~~~~~
672+
673+Type Class Instances
674+~~~~~~~~~~~~~~~~~~~~
675+
676+Values
677+~~~~~~
678+
679+::
680+
681+ catchError :: forall a. forall r. forall e. Prelude.Function e (Eff r a) -> Eff err :: Error e | r a -> Eff r a
682+
683+ throwError :: forall r. forall e. forall a. e -> Eff err :: Error e | r a
684+
685+Module IORef
686+------------
687+
688+Types
689+~~~~~
690+
691+::
692+
693+ data IORef :: * -> *
694+
695+ data Ref :: !
696+
697+Type Classes
698+~~~~~~~~~~~~
699+
700+Type Class Instances
701+~~~~~~~~~~~~~~~~~~~~
702+
703+Values
704+~~~~~~
705+
706+::
707+
708+ modifyIORef :: forall r. forall s. IORef s -> Prelude.Function s s -> Eff ref :: Ref | r { }
709+
710+ newIORef :: forall r. forall s. s -> Eff ref :: Ref | r (IORef s)
711+
712+ readIORef :: forall r. forall s. IORef s -> Eff ref :: Ref | r s
713+
714+ writeIORef :: forall r. forall s. IORef s -> s -> Eff ref :: Ref | r { }
715+
84−Trace Module
716+Module Trace
85------------
717------------
86
718
87−`TODO`
719+Types
88−
720+~~~~~
721+
722+::
723+
724+ data Trace :: !
725+
726+Type Classes
727+~~~~~~~~~~~~
728+
729+Type Class Instances
730+~~~~~~~~~~~~~~~~~~~~
731+
732+Values
733+~~~~~~
734+
735+::
736+
737+ print :: forall r. forall a. (Prelude.Show (a)) => a -> Eff trace :: Trace | r { }
738+
739+ trace :: forall r. Prelude.String -> Eff trace :: Trace | r { }
740+
741+Module ST
742+---------
743+
744+Types
745+~~~~~
746+
747+::
748+
749+ data ST :: * -> !
750+
751+ data STRef :: * -> * -> *
752+
753+Type Classes
754+~~~~~~~~~~~~
755+
756+Type Class Instances
757+~~~~~~~~~~~~~~~~~~~~
758+
759+Values
760+~~~~~~
761+
762+::
763+
764+ modifySTRef :: forall r. forall h. forall a. STRef h a -> Prelude.Function a a -> Eff st :: ST h | r { }
765+
766+ newSTRef :: forall r. forall h. forall a. a -> Eff st :: ST h | r (STRef h a)
767+
768+ readSTRef :: forall r. forall h. forall a. STRef h a -> Eff st :: ST h | r a
769+
770+ runST :: forall r. forall a. forall h. Eff st :: ST h | r a -> Eff r a
771+
772+ writeSTRef :: forall r. forall h. forall a. STRef h a -> a -> Eff st :: ST h | r { }
773+
examples/failing/SkolemEscape2.pursnew file+9
@@ -0,0 +1,9 @@
1+module SkolemEscape where
2+
3+import Prelude
4+import Eff
5+import ST
6+
7+test _ = do
8+ r <- runST (newSTRef 0)
9+ ret 0
examples/passing/Do.purs−16
@@ -42,22 +42,6 @@ test8 = \_ -> do
42 Just (do
42 Just (do
43 Just 1)
43 Just 1)
44
44
45−(<$>) :: forall a b. (a -> b) -> Maybe a -> Maybe b
46−(<$>) f m = do
47− a <- m
48− ret (f a)
49−
50−(<*>) :: forall a b. (Maybe (a -> b)) -> Maybe a -> Maybe b
51−(<*>) f m = do
52− g <- f
53− a <- m
54− ret (g a)
55−
56−forever :: forall m a b. (Monad m) => m a -> m b
57−forever a = do
58− a
59− forever a
60−
61test9 = \_ -> (+) <$> Just 1 <*> Just 2
45test9 = \_ -> (+) <$> Just 1 <*> Just 2
62
46
63module Main where
47module Main where
examples/passing/Eff.purs+3−3
@@ -10,10 +10,10 @@ test1 = catchError (\s -> ret 0) $ do
10 trace "Testing"
10 trace "Testing"
11 throwError "Error!"
11 throwError "Error!"
12
12
13−test2 = runPure $ runST $ do
13+test2 = runPure (runST (do
14 ref <- newSTRef 0
14 ref <- newSTRef 0
15 modifySTRef ref $ \n -> n + 1
15 modifySTRef ref $ \n -> n + 1
16− readSTRef ref
16+ readSTRef ref))
17
17
18module Main where
18module Main where
19
19
@@ -24,4 +24,4 @@ import TestEff
24main = do
24main = do
25 n <- test1
25 n <- test1
26 Trace.print n
26 Trace.print n
27− Trace.print test2
27+ --Trace.print test2
examples/passing/Monad.purs+1−1
@@ -1,4 +1,4 @@
1−module Monad where
1+module MonadTest where
2
2
3 type Monad m = { ret :: forall a. a -> m a
3 type Monad m = { ret :: forall a. a -> m a
4 , bind :: forall a b. m a -> (a -> m b) -> m b }
4 , bind :: forall a b. m a -> (a -> m b) -> m b }
libraries/prelude/README.mdnew file+683
@@ -0,0 +1,683 @@
1+# Module Documentation
2+## Module Prelude
3+
4+### Types
5+
6+ data Array :: * -> *
7+
8+ data Boolean :: *
9+
10+ data Function :: * -> * -> *
11+
12+ data Number :: *
13+
14+ data Ref a where
15+ Ref :: a -> Ref a
16+
17+ data String :: *
18+
19+
20+### Type Classes
21+
22+ class Alternative f where
23+ empty :: forall a. f a
24+ (<|>) :: forall a. f a -> f a -> f a
25+
26+ class Applicative f where
27+ pure :: forall a. a -> f a
28+ (<*>) :: forall b. forall a. f (a -> b) -> f a -> f b
29+
30+ class Bits b where
31+ (&) :: b -> b -> b
32+ (|) :: b -> b -> b
33+ (^) :: b -> b -> b
34+ shl :: b -> Prelude.Number -> b
35+ shr :: b -> Prelude.Number -> b
36+ zshr :: b -> Prelude.Number -> b
37+ complement :: b -> b
38+
39+ class BoolLike b where
40+ (&&) :: b -> b -> b
41+ (||) :: b -> b -> b
42+ not :: b -> b
43+
44+ class Category a where
45+ id :: forall t. a t t
46+ (<<<) :: forall d. forall c. forall b. a c d -> a b c -> a b d
47+ (>>>) :: forall d. forall c. forall b. a b c -> a c d -> a b d
48+
49+ class Eq a where
50+ (==) :: a -> a -> Prelude.Boolean
51+ (/=) :: a -> a -> Prelude.Boolean
52+
53+ class Functor f where
54+ (<$>) :: forall b. forall a. Prelude.Function a b -> f a -> f b
55+
56+ class Monad m where
57+ ret :: forall a. a -> m a
58+ (>>=) :: forall b. forall a. m a -> Prelude.Function a (m b) -> m b
59+
60+ class Num a where
61+ (+) :: a -> a -> a
62+ (-) :: a -> a -> a
63+ (*) :: a -> a -> a
64+ (/) :: a -> a -> a
65+ (%) :: a -> a -> a
66+ negate :: a -> a
67+
68+ class Ord a where
69+ (<) :: a -> a -> Prelude.Boolean
70+ (>) :: a -> a -> Prelude.Boolean
71+ (<=) :: a -> a -> Prelude.Boolean
72+ (>=) :: a -> a -> Prelude.Boolean
73+
74+ class Read a where
75+ read :: Prelude.String -> a
76+
77+ class Show a where
78+ show :: a -> Prelude.String
79+
80+
81+### Type Class Instances
82+
83+ (Monad (m)) => instance Applicative m
84+
85+ instance Bits Prelude.Number
86+
87+ instance BoolLike Prelude.Boolean
88+
89+ instance Category Prelude.Function
90+
91+ instance Eq Ref a
92+
93+ instance Eq Prelude.String
94+
95+ instance Eq Prelude.Number
96+
97+ instance Eq Prelude.Boolean
98+
99+ (Eq (a)) => instance Eq Prelude.Array a
100+
101+ (Applicative (f)) => instance Functor f
102+
103+ instance Num Prelude.Number
104+
105+ instance Ord Prelude.Number
106+
107+ instance Prelude.Show Prelude.Number
108+
109+ instance Read Prelude.String
110+
111+ instance Read Prelude.Boolean
112+
113+ instance Show Prelude.String
114+
115+ instance Show Prelude.Boolean
116+
117+
118+### Values
119+
120+ (!!) :: forall a. Prelude.Array a -> Prelude.Number -> a
121+
122+ (#) :: forall b. forall a. a -> Prelude.Function a b -> b
123+
124+ ($) :: forall b. forall a. Prelude.Function a b -> a -> b
125+
126+ (++) :: Prelude.String -> Prelude.String -> Prelude.String
127+
128+ boolAnd :: Prelude.Boolean -> Prelude.Boolean -> Prelude.Boolean
129+
130+ boolNot :: Prelude.Boolean -> Prelude.Boolean
131+
132+ boolOr :: Prelude.Boolean -> Prelude.Boolean -> Prelude.Boolean
133+
134+ flip :: forall c. forall b. forall a. Prelude.Function a (b -> c) -> b -> a -> c
135+
136+ konst :: forall b. forall a. a -> b -> a
137+
138+ numAdd :: Prelude.Number -> Prelude.Number -> Prelude.Number
139+
140+ numAnd :: Prelude.Number -> Prelude.Number -> Prelude.Number
141+
142+ numComplement :: Prelude.Number -> Prelude.Number
143+
144+ numDiv :: Prelude.Number -> Prelude.Number -> Prelude.Number
145+
146+ numGreater :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
147+
148+ numGreaterEq :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
149+
150+ numLess :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
151+
152+ numLessEq :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
153+
154+ numMod :: Prelude.Number -> Prelude.Number -> Prelude.Number
155+
156+ numMul :: Prelude.Number -> Prelude.Number -> Prelude.Number
157+
158+ numNegate :: Prelude.Number -> Prelude.Number
159+
160+ numOr :: Prelude.Number -> Prelude.Number -> Prelude.Number
161+
162+ numShl :: Prelude.Number -> Prelude.Number -> Prelude.Number
163+
164+ numShr :: Prelude.Number -> Prelude.Number -> Prelude.Number
165+
166+ numSub :: Prelude.Number -> Prelude.Number -> Prelude.Number
167+
168+ numXor :: Prelude.Number -> Prelude.Number -> Prelude.Number
169+
170+ numZshr :: Prelude.Number -> Prelude.Number -> Prelude.Number
171+
172+ refEq :: forall a. Ref a -> Ref a -> Prelude.Boolean
173+
174+ refIneq :: forall a. Ref a -> Ref a -> Prelude.Boolean
175+
176+ showNumber :: Prelude.Number -> Prelude.String
177+
178+ unsafeRefEq :: forall a. a -> a -> Prelude.Boolean
179+
180+ unsafeRefIneq :: forall a. a -> a -> Prelude.Boolean
181+
182+
183+## Module Monoid
184+
185+### Types
186+
187+
188+### Type Classes
189+
190+ class Monoid m where
191+ mempty :: m
192+ (<>) :: m -> m -> m
193+
194+
195+### Type Class Instances
196+
197+ instance Monoid Prelude.String
198+
199+
200+### Values
201+
202+ mconcat :: forall m. (Monoid (m)) => Prelude.Array m -> m
203+
204+
205+## Module Monad
206+
207+### Types
208+
209+
210+### Type Classes
211+
212+
213+### Type Class Instances
214+
215+
216+### Values
217+
218+ (<=<) :: forall c. forall b. forall a. forall m. (Monad (m)) => Prelude.Function b (m c) -> Prelude.Function a (m b) -> a -> m c
219+
220+ (>=>) :: forall c. forall b. forall a. forall m. (Monad (m)) => Prelude.Function a (m b) -> Prelude.Function b (m c) -> a -> m c
221+
222+ foldM :: forall b. forall a. forall m. (Monad (m)) => Prelude.Function a (b -> m a) -> a -> Prelude.Array b -> m a
223+
224+ join :: forall a. forall m. (Monad (m)) => m (m a) -> m a
225+
226+ mapM :: forall b. forall a. forall m. (Monad (m)) => Prelude.Function a (m b) -> Prelude.Array a -> m [b]
227+
228+ replicateM :: forall a. forall m. (Monad (m)) => Prelude.Number -> m a -> m [a]
229+
230+ sequence :: forall a. forall m. (Monad (m)) => Prelude.Array (m a) -> m [a]
231+
232+ when :: forall m. (Monad (m)) => Prelude.Boolean -> m { } -> m { }
233+
234+
235+## Module Maybe
236+
237+### Types
238+
239+ data Maybe a where
240+ Nothing :: Maybe a
241+ Just :: a -> Maybe a
242+
243+
244+### Type Classes
245+
246+
247+### Type Class Instances
248+
249+ instance Prelude.Monad Maybe
250+
251+
252+### Values
253+
254+ fromMaybe :: forall a. a -> Maybe a -> a
255+
256+ maybe :: forall b. forall a. b -> Prelude.Function a b -> Maybe a -> b
257+
258+
259+## Module Either
260+
261+### Types
262+
263+ data Either a b where
264+ Left :: a -> Either a b
265+ Right :: b -> Either a b
266+
267+
268+### Type Classes
269+
270+
271+### Type Class Instances
272+
273+ instance Prelude.Monad Either e
274+
275+
276+### Values
277+
278+ either :: forall c. forall b. forall a. Prelude.Function a c -> Prelude.Function b c -> Either a b -> c
279+
280+
281+## Module Arrays
282+
283+### Types
284+
285+
286+### Type Classes
287+
288+
289+### Type Class Instances
290+
291+ instance Prelude.Alternative Prelude.Array
292+
293+ instance Prelude.Monad Prelude.Array
294+
295+ (Prelude.Show (a)) => instance Prelude.Show Prelude.Array a
296+
297+
298+### Values
299+
300+ (:) :: forall a. a -> Prelude.Array a -> Prelude.Array a
301+
302+ all :: forall a. Prelude.Function a Prelude.Boolean -> Prelude.Array a -> Prelude.Boolean
303+
304+ any :: forall a. Prelude.Function a Prelude.Boolean -> Prelude.Array a -> Prelude.Boolean
305+
306+ concat :: forall a. Prelude.Array a -> Prelude.Array a -> Prelude.Array a
307+
308+ concatMap :: forall b. forall a. Prelude.Array a -> Prelude.Function a [b] -> Prelude.Array b
309+
310+ filter :: forall a. Prelude.Function a Prelude.Boolean -> Prelude.Array a -> Prelude.Array a
311+
312+ foldl :: forall b. forall a. Prelude.Function a (b -> b) -> b -> Prelude.Array a -> b
313+
314+ foldr :: forall b. forall a. Prelude.Function a (b -> a) -> a -> Prelude.Array b -> a
315+
316+ head :: forall a. Prelude.Array a -> a
317+
318+ headSafe :: forall a. Prelude.Array a -> Maybe a
319+
320+ indexOf :: forall a. Prelude.Array a -> a -> Prelude.Number
321+
322+ isEmpty :: forall a. Prelude.Array a -> Prelude.Boolean
323+
324+ joinS :: Prelude.Array Prelude.String -> Prelude.String
325+
326+ joinWith :: Prelude.Array Prelude.String -> Prelude.String -> Prelude.String
327+
328+ lastIndexOf :: forall a. Prelude.Array a -> a -> Prelude.Number
329+
330+ length :: forall a. Prelude.Array a -> Prelude.Number
331+
332+ map :: forall b. forall a. Prelude.Function a b -> Prelude.Array a -> Prelude.Array b
333+
334+ push :: forall a. Prelude.Array a -> a -> Prelude.Array a
335+
336+ range :: Prelude.Number -> Prelude.Number -> Prelude.Array Prelude.Number
337+
338+ reverse :: forall a. Prelude.Array a -> Prelude.Array a
339+
340+ shift :: forall a. Prelude.Array a -> Prelude.Array a
341+
342+ singleton :: forall a. a -> Prelude.Array a
343+
344+ slice :: forall a. Prelude.Number -> Prelude.Number -> Prelude.Array a -> Prelude.Array a
345+
346+ sort :: forall a. Prelude.Array a -> Prelude.Array a
347+
348+ splice :: forall a. Prelude.Number -> Prelude.Number -> Prelude.Array a -> Prelude.Array a -> Prelude.Array a
349+
350+ tail :: forall a. Prelude.Array a -> Prelude.Array a
351+
352+ tailSafe :: forall a. Prelude.Array a -> Maybe [a]
353+
354+ zipWith :: forall c. forall b. forall a. Prelude.Function a (b -> c) -> Prelude.Array a -> Prelude.Array b -> Prelude.Array c
355+
356+
357+## Module Tuple
358+
359+### Types
360+
361+ type Tuple a b = { snd :: b, fst :: a }
362+
363+
364+### Type Classes
365+
366+
367+### Type Class Instances
368+
369+
370+### Values
371+
372+ curry :: forall c. forall b. forall a. Prelude.Function (Tuple a b) c -> a -> b -> c
373+
374+ tuple :: forall b. forall a. a -> b -> Tuple a b
375+
376+ uncurry :: forall c. forall b. forall a. Prelude.Function a (b -> c) -> Tuple a b -> c
377+
378+ unzip :: forall b. forall a. Prelude.Array (Tuple a b) -> Tuple [a] [b]
379+
380+ zip :: forall b. forall a. Prelude.Array a -> Prelude.Array b -> Prelude.Array (Tuple a b)
381+
382+
383+## Module String
384+
385+### Types
386+
387+
388+### Type Classes
389+
390+
391+### Type Class Instances
392+
393+
394+### Values
395+
396+ charAt :: Prelude.Number -> Prelude.String -> Prelude.String
397+
398+ indexOfS :: Prelude.String -> Prelude.String -> Prelude.Number
399+
400+ lastIndexOfS :: Prelude.String -> Prelude.String -> Prelude.Number
401+
402+ lengthS :: Prelude.String -> Prelude.Number
403+
404+ localeCompare :: Prelude.String -> Prelude.String -> Prelude.Number
405+
406+ replace :: Prelude.String -> Prelude.String -> Prelude.String -> Prelude.String
407+
408+ sliceS :: Prelude.Number -> Prelude.Number -> Prelude.String -> Prelude.String
409+
410+ split :: Prelude.String -> Prelude.String -> Prelude.Array Prelude.String
411+
412+ substr :: Prelude.Number -> Prelude.Number -> Prelude.String -> Prelude.String
413+
414+ substring :: Prelude.Number -> Prelude.Number -> Prelude.String -> Prelude.String
415+
416+ toLower :: Prelude.String -> Prelude.String
417+
418+ toUpper :: Prelude.String -> Prelude.String
419+
420+ trim :: Prelude.String -> Prelude.String
421+
422+
423+## Module Regex
424+
425+### Types
426+
427+ data Regex :: *
428+
429+
430+### Type Classes
431+
432+
433+### Type Class Instances
434+
435+
436+### Values
437+
438+ match :: Regex -> Prelude.String -> Prelude.Array Prelude.String
439+
440+ regex :: Prelude.String -> Prelude.String -> Regex
441+
442+ replaceR :: Regex -> Prelude.String -> Prelude.String -> Prelude.String
443+
444+ search :: Regex -> Prelude.String -> Prelude.Number
445+
446+ test :: Regex -> Prelude.String -> Prelude.Boolean
447+
448+
449+## Module Global
450+
451+### Types
452+
453+
454+### Type Classes
455+
456+
457+### Type Class Instances
458+
459+
460+### Values
461+
462+ decodeURI :: Prelude.String -> Prelude.String
463+
464+ decodeURIComponent :: Prelude.String -> Prelude.String
465+
466+ encodeURI :: Prelude.String -> Prelude.String
467+
468+ encodeURIComponent :: Prelude.String -> Prelude.String
469+
470+ infinity :: Prelude.Number
471+
472+ isFinite :: Prelude.Number -> Prelude.Boolean
473+
474+ isNaN :: Prelude.Number -> Prelude.Boolean
475+
476+ nan :: Prelude.Number
477+
478+ parseFloat :: Prelude.String -> Prelude.Number
479+
480+ parseInt :: Prelude.String -> Prelude.Number
481+
482+ toExponential :: Prelude.Number -> Prelude.String
483+
484+ toFixed :: Prelude.Number -> Prelude.Number -> Prelude.String
485+
486+ toPrecision :: Prelude.Number -> Prelude.Number -> Prelude.String
487+
488+
489+## Module Math
490+
491+### Types
492+
493+
494+### Type Classes
495+
496+
497+### Type Class Instances
498+
499+
500+### Values
501+
502+ abs :: Prelude.Number -> Prelude.Number
503+
504+ aceil :: Prelude.Number -> Prelude.Number
505+
506+ acos :: Prelude.Number -> Prelude.Number
507+
508+ asin :: Prelude.Number -> Prelude.Number
509+
510+ atan :: Prelude.Number -> Prelude.Number
511+
512+ atan2 :: Prelude.Number -> Prelude.Number -> Prelude.Number
513+
514+ cos :: Prelude.Number -> Prelude.Number
515+
516+ exp :: Prelude.Number -> Prelude.Number
517+
518+ floor :: Prelude.Number -> Prelude.Number
519+
520+ log :: Prelude.Number -> Prelude.Number
521+
522+ max :: Prelude.Number -> Prelude.Number
523+
524+ min :: Prelude.Number -> Prelude.Number
525+
526+ pow :: Prelude.Number -> Prelude.Number
527+
528+ round :: Prelude.Number -> Prelude.Number
529+
530+ sin :: Prelude.Number -> Prelude.Number
531+
532+ sqrt :: Prelude.Number -> Prelude.Number
533+
534+ tan :: Prelude.Number -> Prelude.Number
535+
536+
537+## Module Eff
538+
539+### Types
540+
541+ data Eff :: # ! -> * -> *
542+
543+ type Pure a = forall e. Eff e a
544+
545+
546+### Type Classes
547+
548+
549+### Type Class Instances
550+
551+ instance Prelude.Monad Eff e
552+
553+
554+### Values
555+
556+ bindEff :: forall b. forall a. forall e. Eff e a -> Prelude.Function a (Eff e b) -> Eff e b
557+
558+ forE :: forall e. Prelude.Number -> Prelude.Number -> Prelude.Function Prelude.Number (Eff e { }) -> Eff e { }
559+
560+ foreachE :: forall a. forall e. Prelude.Array a -> Prelude.Function a (Eff e { }) -> Eff e { }
561+
562+ retEff :: forall a. forall e. a -> Eff e a
563+
564+ runPure :: forall a. Pure a -> a
565+
566+ untilE :: forall e. Eff e Prelude.Boolean -> Eff e { }
567+
568+ whileE :: forall e. Eff e Prelude.Boolean -> Eff e { } -> Eff e { }
569+
570+
571+## Module Random
572+
573+### Types
574+
575+ data Random :: !
576+
577+
578+### Type Classes
579+
580+
581+### Type Class Instances
582+
583+
584+### Values
585+
586+ random :: forall e. Eff random :: Random | e Prelude.Number
587+
588+
589+## Module Errors
590+
591+### Types
592+
593+ data Error :: * -> !
594+
595+
596+### Type Classes
597+
598+
599+### Type Class Instances
600+
601+
602+### Values
603+
604+ catchError :: forall a. forall r. forall e. Prelude.Function e (Eff r a) -> Eff err :: Error e | r a -> Eff r a
605+
606+ throwError :: forall r. forall e. forall a. e -> Eff err :: Error e | r a
607+
608+
609+## Module IORef
610+
611+### Types
612+
613+ data IORef :: * -> *
614+
615+ data Ref :: !
616+
617+
618+### Type Classes
619+
620+
621+### Type Class Instances
622+
623+
624+### Values
625+
626+ modifyIORef :: forall r. forall s. IORef s -> Prelude.Function s s -> Eff ref :: Ref | r { }
627+
628+ newIORef :: forall r. forall s. s -> Eff ref :: Ref | r (IORef s)
629+
630+ readIORef :: forall r. forall s. IORef s -> Eff ref :: Ref | r s
631+
632+ writeIORef :: forall r. forall s. IORef s -> s -> Eff ref :: Ref | r { }
633+
634+
635+## Module Trace
636+
637+### Types
638+
639+ data Trace :: !
640+
641+
642+### Type Classes
643+
644+
645+### Type Class Instances
646+
647+
648+### Values
649+
650+ print :: forall r. forall a. (Prelude.Show (a)) => a -> Eff trace :: Trace | r { }
651+
652+ trace :: forall r. Prelude.String -> Eff trace :: Trace | r { }
653+
654+
655+## Module ST
656+
657+### Types
658+
659+ data ST :: * -> !
660+
661+ data STRef :: * -> * -> *
662+
663+
664+### Type Classes
665+
666+
667+### Type Class Instances
668+
669+
670+### Values
671+
672+ modifySTRef :: forall r. forall h. forall a. STRef h a -> Prelude.Function a a -> Eff st :: ST h | r { }
673+
674+ newSTRef :: forall r. forall h. forall a. a -> Eff st :: ST h | r (STRef h a)
675+
676+ readSTRef :: forall r. forall h. forall a. STRef h a -> Eff st :: ST h | r a
677+
678+ runST :: forall r. forall a. forall h. Eff st :: ST h | r a -> Eff r a
679+
680+ writeSTRef :: forall r. forall h. forall a. STRef h a -> a -> Eff st :: ST h | r { }
681+
682+
683+
libraries/prelude/prelude.purs+153−9
@@ -61,10 +61,37 @@ module Prelude where
61 read "true" = true
61 read "true" = true
62 read _ = false
62 read _ = false
63
63
64+ infixl 4 <$>
65+
66+ class Functor f where
67+ (<$>) :: forall a b. (a -> b) -> f a -> f b
68+
69+ infixl 4 <*>
70+
71+ class Applicative f where
72+ pure :: forall a. a -> f a
73+ (<*>) :: forall a b. f (a -> b) -> f a -> f b
74+
75+ instance (Applicative f) => Functor f where
76+ (<$>) f a = pure f <*> a
77+
78+ infixl 3 <|>
79+
80+ class Alternative f where
81+ empty :: forall a. f a
82+ (<|>) :: forall a. f a -> f a -> f a
83+
64 class Monad m where
84 class Monad m where
65 ret :: forall a. a -> m a
85 ret :: forall a. a -> m a
66 (>>=) :: forall a b. m a -> (a -> m b) -> m b
86 (>>=) :: forall a b. m a -> (a -> m b) -> m b
67
87
88+ instance (Monad m) => Applicative m where
89+ pure = ret
90+ (<*>) f a = do
91+ f' <- f
92+ a' <- a
93+ ret (f' a')
94+
68 infixl 5 *
95 infixl 5 *
69 infixl 5 /
96 infixl 5 /
70 infixl 5 %
97 infixl 5 %
@@ -326,6 +353,74 @@ module Prelude where
326 \ };\
353 \ };\
327 \}" :: String -> String -> String
354 \}" :: String -> String -> String
328
355
356+module Monoid where
357+
358+ import Prelude
359+
360+ infixr 6 <>
361+
362+ class Monoid m where
363+ mempty :: m
364+ (<>) :: m -> m -> m
365+
366+ instance Monoid String where
367+ mempty = ""
368+ (<>) = (++)
369+
370+ mconcat :: forall m. (Monoid m) => [m] -> m
371+ mconcat [] = mempty
372+ mconcat (m:ms) = m <> mconcat ms
373+
374+module Monad where
375+
376+ import Prelude
377+ import Arrays
378+
379+ replicateM :: forall m a. (Monad m) => Number -> m a -> m [a]
380+ replicateM 0 _ = ret []
381+ replicateM n m = do
382+ a <- m
383+ as <- replicateM (n - 1) m
384+ ret (a : as)
385+
386+ mapM :: forall m a b. (Monad m) => (a -> m b) -> [a] -> m [b]
387+ mapM _ [] = ret []
388+ mapM f (a:as) = do
389+ b <- f a
390+ bs <- mapM f as
391+ ret (b : bs)
392+
393+ infixr 1 >=>
394+ infixr 1 <=<
395+
396+ (>=>) :: forall m a b c. (Monad m) => (a -> m b) -> (b -> m c) -> a -> m c
397+ (>=>) f g a = do
398+ b <- f a
399+ g b
400+
401+ (<=<) :: forall m a b c. (Monad m) => (b -> m c) -> (a -> m b) -> a -> m c
402+ (<=<) = flip (>=>)
403+
404+ sequence :: forall m a. (Monad m) => [m a] -> m [a]
405+ sequence [] = ret []
406+ sequence (m:ms) = do
407+ a <- m
408+ as <- sequence ms
409+ ret (a : as)
410+
411+ join :: forall m a. (Monad m) => m (m a) -> m a
412+ join mm = do
413+ m <- mm
414+ m
415+
416+ foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
417+ foldM _ a [] = ret a
418+ foldM f a (b:bs) = f a b >>= \a' -> foldM f a' bs
419+
420+ when :: forall m. (Monad m) => Boolean -> m {} -> m {}
421+ when true m = m
422+ when false _ = ret {}
423+
329module Maybe where
424module Maybe where
330
425
331 import Prelude
426 import Prelude
@@ -408,9 +503,9 @@ module Arrays where
408 \ };\
503 \ };\
409 \}" :: forall a. [a] -> [a] -> [a]
504 \}" :: forall a. [a] -> [a] -> [a]
410
505
411− foreign import join "function join(l) {\
506+ foreign import joinS "function joinS(l) {\
412− \ return l.join();\
507+ \ return l.join();\
413− \}" :: [String] -> String
508+ \}" :: [String] -> String
414
509
415 foreign import joinWith "function joinWith(l) {\
510 foreign import joinWith "function joinWith(l) {\
416 \ return function (s) {\
511 \ return function (s) {\
@@ -467,6 +562,9 @@ module Arrays where
467 (:) :: forall a. a -> [a] -> [a]
562 (:) :: forall a. a -> [a] -> [a]
468 (:) a = concat [a]
563 (:) a = concat [a]
469
564
565+ singleton :: forall a. a -> [a]
566+ singleton a = [a]
567+
470 concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
568 concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
471 concatMap [] f = []
569 concatMap [] f = []
472 concatMap (a:as) f = f a `concat` concatMap as f
570 concatMap (a:as) f = f a `concat` concatMap as f
@@ -476,9 +574,9 @@ module Arrays where
476 filter p (x:xs) | p x = x : filter p xs
574 filter p (x:xs) | p x = x : filter p xs
477 filter p (_:xs) = filter p xs
575 filter p (_:xs) = filter p xs
478
576
479− empty :: forall a. [a] -> Boolean
577+ isEmpty :: forall a. [a] -> Boolean
480− empty [] = true
578+ isEmpty [] = true
481− empty _ = false
579+ isEmpty _ = false
482
580
483 range :: Number -> Number -> [Number]
581 range :: Number -> Number -> [Number]
484 range lo hi = {
582 range lo hi = {
@@ -505,6 +603,14 @@ module Arrays where
505 show [] = "[]"
603 show [] = "[]"
506 show (x:xs) = show x ++ " : " ++ show xs
604 show (x:xs) = show x ++ " : " ++ show xs
507
605
606+ instance Prelude.Monad [] where
607+ ret = singleton
608+ (>>=) = concatMap
609+
610+ instance Prelude.Alternative [] where
611+ empty = []
612+ (<|>) = concat
613+
508module Tuple where
614module Tuple where
509
615
510 import Prelude
616 import Prelude
@@ -783,6 +889,46 @@ module Eff where
783 ret = retEff
889 ret = retEff
784 (>>=) = bindEff
890 (>>=) = bindEff
785
891
892+ foreign import untilE "function untilE(f) {\
893+ \ return function() {\
894+ \ while (!f()) { }\
895+ \ return {};\
896+ \ };\
897+ \}" :: forall e. Eff e Boolean -> Eff e {}
898+
899+ foreign import whileE "function whileE(f) {\
900+ \ return function(a) {\
901+ \ return function() {\
902+ \ while (f()) {\
903+ \ a();\
904+ \ }\
905+ \ return {};\
906+ \ };\
907+ \ };\
908+ \}" :: forall e. Eff e Boolean -> Eff e {} -> Eff e {}
909+
910+ foreign import forE "function forE(lo) {\
911+ \ return function(hi) {\
912+ \ return function(f) {\
913+ \ return function() {\
914+ \ for (var i = lo; i < hi; i++) {\
915+ \ f(i)();\
916+ \ }\
917+ \ };\
918+ \ };\
919+ \ };\
920+ \}" :: forall e. Number -> Number -> (Number -> Eff e {}) -> Eff e {}
921+
922+
923+ foreign import foreachE "function foreachE(as) {\
924+ \ return function(f) {\
925+ \ for (var i = 0; i < as.length; i++) {\
926+ \ f(as[i])();\
927+ \ }\
928+ \ };\
929+ \}" :: forall e a. [a] -> (a -> Eff e {}) -> Eff e {}
930+
931+
786module Random where
932module Random where
787
933
788 import Eff
934 import Eff
@@ -790,9 +936,7 @@ module Random where
790 foreign import data Random :: !
936 foreign import data Random :: !
791
937
792 foreign import random "function random() {\
938 foreign import random "function random() {\
793− \ return function() {\
794− \ return Math.random();\
939+ \ return Math.random();\
795− \ };\
796 \}" :: forall e. Eff (random :: Random | e) Number
940 \}" :: forall e. Eff (random :: Random | e) Number
797
941
798module Errors where
942module Errors where
libraries/prelude/tests/Eff.purs+16−6
@@ -6,11 +6,11 @@ import Errors
6import Trace
6import Trace
7import Global
7import Global
8
8
9−test1 n = runPure $ catchError (\s -> ret 0) $ do
9+test1 n = runPure (catchError (\s -> ret 0) $ do
10 case {} of
10 case {} of
11 _ | n > 10 -> do
11 _ | n > 10 -> do
12 throwError "Error!"
12 throwError "Error!"
13− _ -> ret n
13+ _ -> ret n)
14
14
15test2 = do
15test2 = do
16 trace "Hello World"
16 trace "Hello World"
@@ -38,14 +38,24 @@ test6 s = do
38import ST
38import ST
39
39
40test7 _ = do
40test7 _ = do
41− n <- runST $ do
41+ n <- runST (do
42 r <- newSTRef 0
42 r <- newSTRef 0
43 modifySTRef r $ \n -> n + 1
43 modifySTRef r $ \n -> n + 1
44− readSTRef r
44+ readSTRef r)
45− print $ n
45+ print n
46+
47+test8 _ = (\_1 _2 -> {}) <$> print "Test" <*> print 8
48+
49+test9 _ = do
50+ r <- newSTRef 1
51+ untilE $ do
52+ n <- readSTRef r
53+ trace $ "Count " ++ show n
54+ modifySTRef r $ (+) 1
55+ ret false
46
56
47module Main where
57module Main where
48
58
49import Tests
59import Tests
50
60
51−main = test7 {}
61+main = test9 {}
libraries/prelude/updateDocs.shnew file+2
@@ -0,0 +1,2 @@
1+../../dist/build/docgen/docgen prelude.purs > README.md
2+pandoc -o ../../docs/source/prelude.rst README.md
purescript.cabal+10−1
@@ -1,5 +1,5 @@
1name: purescript
1name: purescript
2−version: 0.3.8.1
2+version: 0.3.9
3cabal-version: >=1.8
3cabal-version: >=1.8
4build-type: Simple
4build-type: Simple
5license: MIT
5license: MIT
@@ -86,6 +86,15 @@ executable psci
86 other-modules:
86 other-modules:
87 ghc-options: -Wall -O2
87 ghc-options: -Wall -O2
88
88
89+executable docgen
90+ build-depends: base >=4 && <5, cmdtheline -any, purescript -any, utf8-string -any,
91+ process -any, mtl -any
92+ main-is: Main.hs
93+ buildable: True
94+ hs-source-dirs: docgen
95+ other-modules:
96+ ghc-options: -Wall -O2
97+
89test-suite tests
98test-suite tests
90 build-depends: base >=4 && <5, containers -any, directory -any,
99 build-depends: base >=4 && <5, containers -any, directory -any,
91 filepath -any, mtl -any, parsec -any, purescript -any, syb -any,
100 filepath -any, mtl -any, parsec -any, purescript -any, syb -any,
src/Language/PureScript/CodeGen/JS.hs+3−3
@@ -128,7 +128,7 @@ runtimeTypeChecks arg ty =
128 where
128 where
129 getFunctionArgumentType :: Type -> Maybe Type
129 getFunctionArgumentType :: Type -> Maybe Type
130 getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
130 getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
131− getFunctionArgumentType (ForAll _ ty') = getFunctionArgumentType ty'
131+ getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
132 getFunctionArgumentType _ = Nothing
132 getFunctionArgumentType _ = Nothing
133 argumentCheck :: JS -> Type -> [JS]
133 argumentCheck :: JS -> Type -> [JS]
134 argumentCheck val t | t == tyNumber = [typeCheck val "number"]
134 argumentCheck val t | t == tyNumber = [typeCheck val "number"]
@@ -141,7 +141,7 @@ runtimeTypeChecks arg ty =
141 in
141 in
142 typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (JSAccessor prop val) ty') pairs
142 typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (JSAccessor prop val) ty') pairs
143 argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
143 argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
144− argumentCheck val (ForAll _ ty') = argumentCheck val ty'
144+ argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
145 argumentCheck _ _ = []
145 argumentCheck _ _ = []
146 typeCheck :: JS -> String -> JS
146 typeCheck :: JS -> String -> JS
147 typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
147 typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
@@ -253,7 +253,7 @@ isOnlyConstructor m e ctor =
253 where
253 where
254 numConstructors ty = length $ filter (\(ty1, _) -> ((==) `on` typeConstructor) ty ty1) $ M.elems $ dataConstructors e
254 numConstructors ty = length $ filter (\(ty1, _) -> ((==) `on` typeConstructor) ty ty1) $ M.elems $ dataConstructors e
255 typeConstructor (TypeConstructor qual) = qualify m qual
255 typeConstructor (TypeConstructor qual) = qualify m qual
256− typeConstructor (ForAll _ ty) = typeConstructor ty
256+ typeConstructor (ForAll _ ty _) = typeConstructor ty
257 typeConstructor (TypeApp (TypeApp t _) ty) | t == tyFunction = typeConstructor ty
257 typeConstructor (TypeApp (TypeApp t _) ty) | t == tyFunction = typeConstructor ty
258 typeConstructor (TypeApp ty _) = typeConstructor ty
258 typeConstructor (TypeApp ty _) = typeConstructor ty
259 typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn
259 typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn
src/Language/PureScript/Pretty/Types.hs+3−3
@@ -36,10 +36,10 @@ typeLiterals = mkPattern match
36 match (TypeApp arr ty) | arr == tyArray = Just $ "[" ++ prettyPrintType ty ++ "]"
36 match (TypeApp arr ty) | arr == tyArray = Just $ "[" ++ prettyPrintType ty ++ "]"
37 match (TypeConstructor ctor) = Just $ show ctor
37 match (TypeConstructor ctor) = Just $ show ctor
38 match (TUnknown (Unknown u)) = Just $ 'u' : show u
38 match (TUnknown (Unknown u)) = Just $ 'u' : show u
39− match (Skolem s) = Just $ 's' : show s
39+ match (Skolem s _) = Just $ 's' : show s
40 match (ConstrainedType deps ty) = Just $ "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ prettyPrintType ty' ++ ")") deps) ++ ") => " ++ prettyPrintType ty
40 match (ConstrainedType deps ty) = Just $ "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ prettyPrintType ty' ++ ")") deps) ++ ") => " ++ prettyPrintType ty
41 match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintType args) ++ ">"
41 match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintType args) ++ ">"
42− match (ForAll ident ty) = Just $ "forall " ++ ident ++ ". " ++ prettyPrintType ty
42+ match (ForAll ident ty _) = Just $ "forall " ++ ident ++ ". " ++ prettyPrintType ty
43 match REmpty = Just $ prettyPrintRow REmpty
43 match REmpty = Just $ prettyPrintRow REmpty
44 match row@(RCons _ _ _) = Just $ prettyPrintRow row
44 match row@(RCons _ _ _) = Just $ prettyPrintRow row
45 match _ = Nothing
45 match _ = Nothing
@@ -56,7 +56,7 @@ prettyPrintRow = (\(tys, rest) -> intercalate ", " (map (uncurry nameAndTypeToPs
56 tailToPs REmpty = ""
56 tailToPs REmpty = ""
57 tailToPs (TUnknown (Unknown u)) = " | u" ++ show u
57 tailToPs (TUnknown (Unknown u)) = " | u" ++ show u
58 tailToPs (TypeVar var) = " | " ++ var
58 tailToPs (TypeVar var) = " | " ++ var
59− tailToPs (Skolem s) = " | s" ++ show s
59+ tailToPs (Skolem s _) = " | s" ++ show s
60 tailToPs _ = error "Invalid row tail"
60 tailToPs _ = error "Invalid row tail"
61 toList :: [(String, Type)] -> Type -> ([(String, Type)], Type)
61 toList :: [(String, Type)] -> Type -> ([(String, Type)], Type)
62 toList tys (RCons name ty row) = toList ((name, ty):tys) row
62 toList tys (RCons name ty row) = toList ((name, ty):tys) row
src/Language/PureScript/Sugar/TypeClasses.hs+2−2
@@ -74,7 +74,7 @@ typeClassMemberToDictionaryAccessor :: ProperName -> String -> Declaration -> De
74typeClassMemberToDictionaryAccessor name arg (TypeDeclaration ident ty) =
74typeClassMemberToDictionaryAccessor name arg (TypeDeclaration ident ty) =
75 ExternDeclaration TypeClassAccessorImport ident
75 ExternDeclaration TypeClassAccessorImport ident
76 (Just (JSFunction (Just $ identToJs ident) ["dict"] (JSBlock [JSReturn (JSAccessor (identToJs ident) (JSVar "dict"))])))
76 (Just (JSFunction (Just $ identToJs ident) ["dict"] (JSBlock [JSReturn (JSAccessor (identToJs ident) (JSVar "dict"))])))
77− (ForAll arg (ConstrainedType [(Qualified Nothing name, TypeVar arg)] ty))
77+ (ForAll arg (ConstrainedType [(Qualified Nothing name, TypeVar arg)] ty) Nothing)
78typeClassMemberToDictionaryAccessor _ _ _ = error "Invalid declaration in type class definition"
78typeClassMemberToDictionaryAccessor _ _ _ = error "Invalid declaration in type class definition"
79
79
80typeInstanceDictionaryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> [Declaration] -> Desugar Declaration
80typeInstanceDictionaryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> [Declaration] -> Desugar Declaration
@@ -120,7 +120,7 @@ qualifiedToString mn (Qualified Nothing pn) = qualifiedToString mn (Qualified (J
120qualifiedToString _ (Qualified (Just (ModuleName mn)) pn) = runProperName mn ++ "_" ++ runProperName pn
120qualifiedToString _ (Qualified (Just (ModuleName mn)) pn) = runProperName mn ++ "_" ++ runProperName pn
121
121
122quantify :: Type -> Type
122quantify :: Type -> Type
123−quantify ty' = foldr ForAll ty' tyVars
123+quantify ty' = foldr (\arg t -> ForAll arg t Nothing) ty' tyVars
124 where
124 where
125 tyVars = nub $ everything (++) (mkQ [] collect) ty'
125 tyVars = nub $ everything (++) (mkQ [] collect) ty'
126 collect (TypeVar v) = [v]
126 collect (TypeVar v) = [v]
src/Language/PureScript/TypeChecker.hs+1−1
@@ -230,7 +230,7 @@ typeCheckAll currentModule (d@(ImportDeclaration moduleName idents) : rest) = do
230 addTypeClassDictionaries [tcd { tcdName = (Qualified (Just currentModule) ident), tcdType = TCDAlias (tcdName tcd) }]
230 addTypeClassDictionaries [tcd { tcdName = (Qualified (Just currentModule) ident), tcdType = TCDAlias (tcdName tcd) }]
231 constructs (TypeConstructor (Qualified (Just mn) pn')) pn
231 constructs (TypeConstructor (Qualified (Just mn) pn')) pn
232 = mn == moduleName && pn' == pn
232 = mn == moduleName && pn' == pn
233− constructs (ForAll _ ty) pn = ty `constructs` pn
233+ constructs (ForAll _ ty _) pn = ty `constructs` pn
234 constructs (TypeApp (TypeApp t _) ty) pn | t == tyFunction = ty `constructs` pn
234 constructs (TypeApp (TypeApp t _) ty) pn | t == tyFunction = ty `constructs` pn
235 constructs (TypeApp ty _) pn = ty `constructs` pn
235 constructs (TypeApp ty _) pn = ty `constructs` pn
236 constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn
236 constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn
src/Language/PureScript/TypeChecker/Kinds.hs+1−1
@@ -142,7 +142,7 @@ infer (TypeApp t1 t2) = do
142 k2 <- infer t2
142 k2 <- infer t2
143 k1 =?= FunKind k2 k0
143 k1 =?= FunKind k2 k0
144 return k0
144 return k0
145−infer (ForAll ident ty) = do
145+infer (ForAll ident ty _) = do
146 k <- fresh
146 k <- fresh
147 Just moduleName <- checkCurrentModule <$> get
147 Just moduleName <- checkCurrentModule <$> get
148 bindLocalTypeVariables moduleName [(ProperName ident, k)] $ infer ty
148 bindLocalTypeVariables moduleName [(ProperName ident, k)] $ infer ty
src/Language/PureScript/TypeChecker/Types.hs+162−100
@@ -45,7 +45,8 @@ import Data.List
45import Data.Maybe (maybeToList, isNothing, isJust, fromMaybe)
45import Data.Maybe (maybeToList, isNothing, isJust, fromMaybe)
46import qualified Data.Data as D
46import qualified Data.Data as D
47import Data.Generics
47import Data.Generics
48+ (everythingWithContext, mkM, everywhereM, everything, mkT,
48− (mkM, everywhereM, everything, mkT, something, everywhere, mkQ)
49+ something, everywhere, mkQ)
49
50
50import Language.PureScript.Values
51import Language.PureScript.Values
51import Language.PureScript.Types
52import Language.PureScript.Types
@@ -66,6 +67,7 @@ import Control.Arrow (Arrow(..))
66
67
67import qualified Data.Map as M
68import qualified Data.Map as M
68import Data.Function (on)
69import Data.Function (on)
70+import Debug.Trace (trace)
69
71
70instance Partial Type where
72instance Partial Type where
71 unknown = TUnknown
73 unknown = TUnknown
@@ -86,17 +88,23 @@ unifyTypes t1 t2 = rethrow (\e -> "Error unifying type " ++ prettyPrintType t1 +
86 unifyTypes' (TUnknown u) t = u =:= t
88 unifyTypes' (TUnknown u) t = u =:= t
87 unifyTypes' t (TUnknown u) = u =:= t
89 unifyTypes' t (TUnknown u) = u =:= t
88 unifyTypes' (SaturatedTypeSynonym name args) ty = do
90 unifyTypes' (SaturatedTypeSynonym name args) ty = do
89− ty1 <- expandTypeSynonym name args
91+ ty1 <- introduceSkolemScope <=< expandTypeSynonym name $ args
90 ty1 `unifyTypes` ty
92 ty1 `unifyTypes` ty
91 unifyTypes' ty s@(SaturatedTypeSynonym _ _) = s `unifyTypes` ty
93 unifyTypes' ty s@(SaturatedTypeSynonym _ _) = s `unifyTypes` ty
92− unifyTypes' (ForAll ident1 ty1) (ForAll ident2 ty2) = do
94+ unifyTypes' (ForAll ident1 ty1 sc1) (ForAll ident2 ty2 sc2) =
95+ case (sc1, sc2) of
96+ (Just sc1', Just sc2') -> do
97+ sko <- newSkolemConstant
93− sk <- skolemize ident1 ty1
98+ let sk1 = skolemize ident1 sko sc1' ty1
94− replaced <- replaceVarWithUnknown ident2 ty2
99+ let sk2 = skolemize ident2 sko sc2' ty2
95− sk `unifyTypes` replaced
100+ sk1 `unifyTypes` sk2
101+ _ -> throwError (prettyPrintType ty1)
96− unifyTypes' (ForAll ident ty1) ty2 = do
102+ unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
103+ sko <- newSkolemConstant
97− sk <- skolemize ident ty1
104+ let sk = skolemize ident sko sc ty1
98 sk `unifyTypes` ty2
105 sk `unifyTypes` ty2
106+ unifyTypes' (ForAll _ _ _) _ = throwError "Skolem variable scope is unspecified"
99− unifyTypes' ty f@(ForAll _ _) = f `unifyTypes` ty
107+ unifyTypes' ty f@(ForAll _ _ _) = f `unifyTypes` ty
100 unifyTypes' (Object row1) (Object row2) = row1 =?= row2
108 unifyTypes' (Object row1) (Object row2) = row1 =?= row2
101 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
109 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
102 unifyTypes' (TypeConstructor c1) (TypeConstructor c2) = do
110 unifyTypes' (TypeConstructor c1) (TypeConstructor c2) = do
@@ -106,7 +114,7 @@ unifyTypes t1 t2 = rethrow (\e -> "Error unifying type " ++ prettyPrintType t1 +
106 unifyTypes' (TypeApp t3 t4) (TypeApp t5 t6) = do
114 unifyTypes' (TypeApp t3 t4) (TypeApp t5 t6) = do
107 t3 `unifyTypes` t5
115 t3 `unifyTypes` t5
108 t4 `unifyTypes` t6
116 t4 `unifyTypes` t6
109− unifyTypes' (Skolem s1) (Skolem s2) | s1 == s2 = return ()
117+ unifyTypes' (Skolem s1 _) (Skolem s2 _) | s1 == s2 = return ()
110 unifyTypes' r1@(RCons _ _ _) r2 = unifyRows r1 r2
118 unifyTypes' r1@(RCons _ _ _) r2 = unifyRows r1 r2
111 unifyTypes' r1 r2@(RCons _ _ _) = unifyRows r1 r2
119 unifyTypes' r1 r2@(RCons _ _ _) = unifyRows r1 r2
112 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
120 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
@@ -143,7 +151,7 @@ unifyRows r1 r2 =
143 unifyRows' row r others u'
151 unifyRows' row r others u'
144 unifyRows' [] REmpty [] REmpty = return ()
152 unifyRows' [] REmpty [] REmpty = return ()
145 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
153 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
146− unifyRows' [] (Skolem s1) [] (Skolem s2) | s1 == s2 = return ()
154+ unifyRows' [] (Skolem s1 _) [] (Skolem s2 _) | s1 == s2 = return ()
147 unifyRows' sd3 r3 sd4 r4 = throwError $ "Cannot unify " ++ prettyPrintRow (rowFromList (sd3, r3)) ++ " with " ++ prettyPrintRow (rowFromList (sd4, r4)) ++ "."
155 unifyRows' sd3 r3 sd4 r4 = throwError $ "Cannot unify " ++ prettyPrintRow (rowFromList (sd3, r3)) ++ " with " ++ prettyPrintRow (rowFromList (sd4, r4)) ++ "."
148
156
149-- |
157-- |
@@ -171,22 +179,24 @@ typesOf moduleName vals = do
171 (ident, (val, Just (ty, checkType))) -> do
179 (ident, (val, Just (ty, checkType))) -> do
172 kind <- liftCheck $ kindOf moduleName ty
180 kind <- liftCheck $ kindOf moduleName ty
173 guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
181 guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
174− ty' <- replaceAllTypeSynonyms ty
182+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
175− val' <- bindNames dict $ if checkType then check val ty' else return val
183+ val' <- bindNames dict $ if checkType
184+ then TypedValue True <$> check val ty' <*> pure ty'
185+ else return (TypedValue False val ty')
176 return (ident, (val', ty'))
186 return (ident, (val', ty'))
177 (ident, (val, Nothing)) -> do
187 (ident, (val, Nothing)) -> do
178 TypedValue _ val' ty <- bindNames dict $ infer val
188 TypedValue _ val' ty <- bindNames dict $ infer val
179 ty =?= fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
189 ty =?= fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
180− return (ident, (val', ty))
190+ return (ident, (TypedValue True val' ty, ty))
181 when (moduleName == ModuleName (ProperName "Main") && fst e == Ident "main") $ do
191 when (moduleName == ModuleName (ProperName "Main") && fst e == Ident "main") $ do
182 [eff, a] <- replicateM 2 fresh
192 [eff, a] <- replicateM 2 fresh
183 ty =?= TypeApp (TypeApp (TypeConstructor (Qualified (Just (ModuleName (ProperName "Eff"))) (ProperName "Eff"))) eff) a
193 ty =?= TypeApp (TypeApp (TypeConstructor (Qualified (Just (ModuleName (ProperName "Eff"))) (ProperName "Eff"))) eff) a
184 escapeCheck val ty
194 escapeCheck val ty
185 return triple
195 return triple
186− forM_ tys $ skolemEscapeCheck . snd . snd
187 forM tys $ \(ident, (val, ty)) -> do
196 forM tys $ \(ident, (val, ty)) -> do
188 val' <- replaceTypeClassDictionaries moduleName val
197 val' <- replaceTypeClassDictionaries moduleName val
198+ rethrow (("Error in " ++ show ident ++ ": \n") ++) $ skolemEscapeCheck val'
189− return (ident, (overTypes (desaturateAllTypeSynonyms . setifyAll) $ val'
199+ return $ (ident, (overTypes (desaturateAllTypeSynonyms . setifyAll) $ val'
190 , varIfUnknown . desaturateAllTypeSynonyms . setifyAll $ ty))
200 , varIfUnknown . desaturateAllTypeSynonyms . setifyAll $ ty))
191 where
201 where
192 tidyUp (ts, sub) = map (\(i, (val, ty)) -> (i, (overTypes (sub $?) val, sub $? ty))) ts
202 tidyUp (ts, sub) = map (\(i, (val, ty)) -> (i, (overTypes (sub $?) val, sub $? ty))) ts
@@ -238,7 +248,7 @@ entails moduleName context goal@(className, ty) = do
238 return $ Just dict
248 return $ Just dict
239 mkDictionary :: Qualified Ident -> Maybe [Value] -> Value
249 mkDictionary :: Qualified Ident -> Maybe [Value] -> Value
240 mkDictionary fnName Nothing = Var fnName
250 mkDictionary fnName Nothing = Var fnName
241− mkDictionary fnName (Just dicts) = foldr (flip App) (Var fnName) dicts
251+ mkDictionary fnName (Just dicts) = foldl App (Var fnName) dicts
242 filterModule :: TypeClassDictionaryInScope -> Bool
252 filterModule :: TypeClassDictionaryInScope -> Bool
243 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
253 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
244 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
254 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
@@ -252,7 +262,9 @@ entails moduleName context goal@(className, ty) = do
252-- and return a substitution from type variables to types which makes the type heads unify.
262-- and return a substitution from type variables to types which makes the type heads unify.
253--
263--
254typeHeadsAreEqual :: ModuleName -> Environment -> Type -> Type -> Maybe [(String, Type)]
264typeHeadsAreEqual :: ModuleName -> Environment -> Type -> Type -> Maybe [(String, Type)]
255−typeHeadsAreEqual _ _ (Skolem s1) (Skolem s2) | s1 == s2 = Just []
265+typeHeadsAreEqual _ _ (Skolem s1 _) (Skolem s2 _) | s1 == s2 = Just []
266+typeHeadsAreEqual _ _ (TypeVar v) t = Just [(v, t)]
267+typeHeadsAreEqual _ _ t (TypeVar v) = Just [(v, t)]
256typeHeadsAreEqual m e (TypeConstructor c1) (TypeConstructor c2) | typeConstructorsAreEqual e m c1 c2 = Just []
268typeHeadsAreEqual m e (TypeConstructor c1) (TypeConstructor c2) | typeConstructorsAreEqual e m c1 c2 = Just []
257typeHeadsAreEqual m e (TypeApp h1 (TypeVar v)) (TypeApp h2 arg) = (:) (v, arg) <$> typeHeadsAreEqual m e h1 h2
269typeHeadsAreEqual m e (TypeApp h1 (TypeVar v)) (TypeApp h2 arg) = (:) (v, arg) <$> typeHeadsAreEqual m e h1 h2
258typeHeadsAreEqual m e t1@(TypeApp _ _) t2@(TypeApp _ (TypeVar _)) = typeHeadsAreEqual m e t2 t1
270typeHeadsAreEqual m e t1@(TypeApp _ _) t2@(TypeApp _ (TypeVar _)) = typeHeadsAreEqual m e t2 t1
@@ -268,7 +280,7 @@ escapeCheck value ty = do
268 let allUnknowns = findAllTypes value
280 let allUnknowns = findAllTypes value
269 forM_ allUnknowns $ \t -> do
281 forM_ allUnknowns $ \t -> do
270 let unsolvedUnknowns = nub . unknowns $ subst $? t
282 let unsolvedUnknowns = nub . unknowns $ subst $? t
271− guardWith ("Escape check fails" ++ show (subst $? ty, subst $? t)) $ null $ unsolvedUnknowns \\ visibleUnknowns
283+ guardWith "Escape check fails" $ null $ unsolvedUnknowns \\ visibleUnknowns
272
284
273-- |
285-- |
274-- Find all type annotations occuring inside a value
286-- Find all type annotations occuring inside a value
@@ -282,14 +294,31 @@ findAllTypes = everything (++) (mkQ [] go)
282-- |
294-- |
283-- Ensure skolem variables do not escape their scope
295-- Ensure skolem variables do not escape their scope
284--
296--
285−skolemEscapeCheck :: Type -> Check ()
297+skolemEscapeCheck :: Value -> Check ()
286−skolemEscapeCheck ty =
298+skolemEscapeCheck (TypedValue False _ _) = return ()
287− case something (mkQ Nothing findSkolems) ty of
299+skolemEscapeCheck root@(TypedValue _ _ _) =
300+ case everythingWithContext [] (++) (mkQ ((,) []) go) root of
288− Nothing -> return ()
301+ [] -> return ()
289− Just _ -> throwError $ "Skolem variables cannot escape. Consider adding a type signature."
302+ ((binding, val) : _) -> throwError $ "Rigid/skolem type variable bound by " ++ maybe "<unknown>" prettyPrintValue binding ++ " has escaped at " ++ prettyPrintValue val
290 where
303 where
291− findSkolems (Skolem _) = return ()
304+ go :: Value -> [(SkolemScope, Value)] -> ([(Maybe Value, Value)], [(SkolemScope, Value)])
292− findSkolems _ = mzero
305+ go val@(TypedValue _ _ (ForAll _ _ (Just sco))) scos = ([], (sco, val) : scos)
306+ go val@(TypedValue _ _ ty) scos = case collectSkolems ty \\ map fst scos of
307+ (sco : _) -> ([(findBindingScope sco, val)], scos)
308+ _ -> ([], scos)
309+ where
310+ collectSkolems :: Type -> [SkolemScope]
311+ collectSkolems = nub . everything (++) (mkQ [] collect)
312+ where
313+ collect (Skolem _ scope) = [scope]
314+ collect _ = []
315+ go _ scos = ([], scos)
316+ findBindingScope :: SkolemScope -> Maybe Value
317+ findBindingScope sco = something (mkQ Nothing go) root
318+ where
319+ go val@(TypedValue _ _ (ForAll _ _ (Just sco'))) | sco == sco' = Just val
320+ go _ = Nothing
321+skolemEscapeCheck val = throwError $ "Untyped value passed to skolemEscapeCheck: " ++ prettyPrintValue val
293
322
294-- |
323-- |
295-- Ensure a row contains no duplicate labels
324-- Ensure a row contains no duplicate labels
@@ -326,7 +355,7 @@ replaceAllTypeVars = foldl' (\f (name, ty) -> replaceTypeVars name ty . f) id
326-- Replace named type variables with new unification variables
355-- Replace named type variables with new unification variables
327--
356--
328replaceAllVarsWithUnknowns :: Type -> UnifyT Type Check Type
357replaceAllVarsWithUnknowns :: Type -> UnifyT Type Check Type
329−replaceAllVarsWithUnknowns (ForAll ident ty) = replaceVarWithUnknown ident ty >>= replaceAllVarsWithUnknowns
358+replaceAllVarsWithUnknowns (ForAll ident ty _) = replaceVarWithUnknown ident ty >>= replaceAllVarsWithUnknowns
330replaceAllVarsWithUnknowns ty = return ty
359replaceAllVarsWithUnknowns ty = return ty
331
360
332-- |
361-- |
@@ -404,7 +433,8 @@ infer' (ObjectUpdate o ps) = do
404 newVals <- zipWith (\(name, _) t -> (name, t)) ps <$> mapM (infer . snd) ps
433 newVals <- zipWith (\(name, _) t -> (name, t)) ps <$> mapM (infer . snd) ps
405 let newTys = map (\(name, TypedValue _ _ ty) -> (name, ty)) newVals
434 let newTys = map (\(name, TypedValue _ _ ty) -> (name, ty)) newVals
406 oldTys <- zip (map fst ps) <$> replicateM (length ps) fresh
435 oldTys <- zip (map fst ps) <$> replicateM (length ps) fresh
407− o' <- check o $ Object $ rowFromList (oldTys, row)
436+ let oldTy = Object $ rowFromList (oldTys, row)
437+ o' <- TypedValue True <$> check o oldTy <*> pure oldTy
408 return $ TypedValue True (ObjectUpdate o' newVals) $ Object $ rowFromList (newTys, row)
438 return $ TypedValue True (ObjectUpdate o' newVals) $ Object $ rowFromList (newTys, row)
409infer' (Accessor prop val) = do
439infer' (Accessor prop val) = do
410 typed@(TypedValue _ _ objTy) <- infer val
440 typed@(TypedValue _ _ objTy) <- infer val
@@ -424,19 +454,17 @@ infer' (Abs arg ret) = do
424 return $ TypedValue True (Abs arg body) $ function ty bodyTy
454 return $ TypedValue True (Abs arg body) $ function ty bodyTy
425infer' (App f arg) = do
455infer' (App f arg) = do
426 f'@(TypedValue _ _ ft) <- infer f
456 f'@(TypedValue _ _ ft) <- infer f
427− ret <- fresh
428− app <- checkFunctionApplication f' ft arg ret
457+ (ret, app) <- checkFunctionApplication f' ft arg
429 return $ TypedValue True app ret
458 return $ TypedValue True app ret
430infer' (Var var) = do
459infer' (Var var) = do
431 Just moduleName <- checkCurrentModule <$> get
460 Just moduleName <- checkCurrentModule <$> get
432− ty <- lookupVariable moduleName var
461+ ty <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
433− ty' <- replaceAllTypeSynonyms ty
434− case ty' of
462+ case ty of
435 ConstrainedType constraints _ -> do
463 ConstrainedType constraints _ -> do
436 env <- getEnv
464 env <- getEnv
437 dicts <- getTypeClassDictionaries
465 dicts <- getTypeClassDictionaries
438− return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty'
466+ return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty
439− _ -> return $ TypedValue True (Var var) ty'
467+ _ -> return $ TypedValue True (Var var) ty
440infer' (Block ss) = do
468infer' (Block ss) = do
441 ret <- fresh
469 ret <- fresh
442 (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
470 (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
@@ -447,7 +475,7 @@ infer' v@(Constructor c) = do
447 Just moduleName <- checkCurrentModule <$> get
475 Just moduleName <- checkCurrentModule <$> get
448 case M.lookup (qualify moduleName c) (dataConstructors env) of
476 case M.lookup (qualify moduleName c) (dataConstructors env) of
449 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
477 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
450− Just (ty, _) -> do ty' <- replaceAllTypeSynonyms ty
478+ Just (ty, _) -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
451 return $ TypedValue True v ty'
479 return $ TypedValue True v ty'
452infer' (Case vals binders) = do
480infer' (Case vals binders) = do
453 ts <- mapM infer vals
481 ts <- mapM infer vals
@@ -464,9 +492,9 @@ infer' (TypedValue checkType val ty) = do
464 Just moduleName <- checkCurrentModule <$> get
492 Just moduleName <- checkCurrentModule <$> get
465 kind <- liftCheck $ kindOf moduleName ty
493 kind <- liftCheck $ kindOf moduleName ty
466 guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
494 guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
467− ty' <- replaceAllTypeSynonyms ty
495+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
468 val' <- if checkType then check val ty' else return val
496 val' <- if checkType then check val ty' else return val
469− return $ TypedValue True val' ty
497+ return $ TypedValue True val' ty'
470infer' _ = error "Invalid argument to infer"
498infer' _ = error "Invalid argument to infer"
471
499
472-- |
500-- |
@@ -477,9 +505,9 @@ inferProperty (Object row) prop = do
477 let (props, _) = rowToList row
505 let (props, _) = rowToList row
478 return $ lookup prop props
506 return $ lookup prop props
479inferProperty (SaturatedTypeSynonym name args) prop = do
507inferProperty (SaturatedTypeSynonym name args) prop = do
480− replaced <- expandTypeSynonym name args
508+ replaced <- introduceSkolemScope <=< expandTypeSynonym name $ args
481 inferProperty replaced prop
509 inferProperty replaced prop
482−inferProperty (ForAll ident ty) prop = do
510+inferProperty (ForAll ident ty _) prop = do
483 replaced <- replaceVarWithUnknown ident ty
511 replaced <- replaceVarWithUnknown ident ty
484 inferProperty replaced prop
512 inferProperty replaced prop
485inferProperty _ _ = return Nothing
513inferProperty _ _ = return Nothing
@@ -551,7 +579,7 @@ checkBinders nvals ret ((binders, grd, val):bs) = do
551 Just moduleName <- checkCurrentModule <$> get
579 Just moduleName <- checkCurrentModule <$> get
552 m1 <- M.unions <$> zipWithM inferBinder nvals binders
580 m1 <- M.unions <$> zipWithM inferBinder nvals binders
553 r <- bindLocalVariables moduleName (M.toList m1) $ do
581 r <- bindLocalVariables moduleName (M.toList m1) $ do
554− val' <- check val ret
582+ val' <- TypedValue True <$> check val ret <*> pure ret
555 case grd of
583 case grd of
556 Nothing -> return (binders, Nothing, val')
584 Nothing -> return (binders, Nothing, val')
557 Just g -> do
585 Just g -> do
@@ -602,7 +630,7 @@ checkStatement mass ret (For ident start end inner) = do
602 return (allCodePathsReturn, mass, For ident start' end' inner')
630 return (allCodePathsReturn, mass, For ident start' end' inner')
603checkStatement mass ret (Return val) = do
631checkStatement mass ret (Return val) = do
604 val' <- check val ret
632 val' <- check val ret
605− return (True, mass, Return val')
633+ return (True, mass, Return (TypedValue True val' ret))
606
634
607-- |
635-- |
608-- Check the type of an if-then-else statement
636-- Check the type of an if-then-else statement
@@ -642,13 +670,32 @@ checkBlock mass ret (s:ss) = do
642 (b, m, ss'') <- checkBlock mass1 ret ss'
670 (b, m, ss'') <- checkBlock mass1 ret ss'
643 return (b, m, s':ss'')
671 return (b, m, s':ss'')
644
672
673+-- |
674+-- Generate a new skolem constant
675+--
676+newSkolemConstant :: UnifyT Type Check Int
677+newSkolemConstant = runUnknown <$> fresh'
678+
679+-- |
680+-- Generate a new skolem scope
681+--
682+newSkolemScope :: UnifyT Type Check SkolemScope
683+newSkolemScope = SkolemScope . runUnknown <$> fresh'
684+
645-- |
685-- |
646-- Skolemize a type variable by replacing its instances with fresh skolem constants
686-- Skolemize a type variable by replacing its instances with fresh skolem constants
647--
687--
688+skolemize :: (D.Data d) => String -> Int -> SkolemScope -> d -> d
689+skolemize ident sko scope d = replaceTypeVars ident (Skolem sko scope) d
690+
691+-- |
692+-- Introduce skolem scope at every occurence of a ForAll
693+--
648−skolemize :: String -> Type -> UnifyT Type Check Type
694+introduceSkolemScope :: Type -> UnifyT Type Check Type
649−skolemize ident ty = do
695+introduceSkolemScope = everywhereM (mkM go)
650− tsk <- Skolem . runUnknown <$> fresh'
696+ where
651− return $ replaceTypeVars ident tsk ty
697+ go (ForAll ident ty Nothing) = ForAll ident ty <$> (Just <$> newSkolemScope)
698+ go other = return other
652
699
653-- |
700-- |
654-- Check the type of a value, rethrowing errors to provide a better error message
701-- Check the type of a value, rethrowing errors to provide a better error message
@@ -668,10 +715,13 @@ check val ty = rethrow errorMessage $ check' val ty
668-- Check the type of a value
715-- Check the type of a value
669--
716--
670check' :: Value -> Type -> UnifyT Type Check Value
717check' :: Value -> Type -> UnifyT Type Check Value
671−check' val (ForAll idents ty) = do
718+check' val t@(ForAll ident ty _) = do
719+ scope <- newSkolemScope
720+ sko <- newSkolemConstant
672− sk <- skolemize idents ty
721+ let sk = skolemize ident sko scope ty
673− check val sk
722+ val' <- check val sk
723+ return $ TypedValue True val' (ForAll ident ty (Just scope))
674−check' val (ConstrainedType constraints ty) = do
724+check' val t@(ConstrainedType constraints ty) = do
675 env <- getEnv
725 env <- getEnv
676 Just moduleName <- checkCurrentModule <$> get
726 Just moduleName <- checkCurrentModule <$> get
677 dictNames <- flip mapM constraints $ \(Qualified _ (ProperName className), _) -> do
727 dictNames <- flip mapM constraints $ \(Qualified _ (ProperName className), _) -> do
@@ -681,34 +731,43 @@ check' val (ConstrainedType constraints ty) = do
681 TypeClassDictionaryInScope name className instanceTy Nothing TCDRegular) (map (Qualified Nothing) dictNames)
731 TypeClassDictionaryInScope name className instanceTy Nothing TCDRegular) (map (Qualified Nothing) dictNames)
682 (qualifyAllUnqualifiedNames moduleName env constraints)) $
732 (qualifyAllUnqualifiedNames moduleName env constraints)) $
683 check val ty
733 check val ty
684− return $ foldr Abs val' dictNames
734+ return $ TypedValue True (foldr Abs val' dictNames) t
735+check' val t@(SaturatedTypeSynonym name args) = do
736+ ty <- introduceSkolemScope <=< expandTypeSynonym name $ args
737+ val' <- check val ty
738+ return $ TypedValue True val' ty
685check' val u@(TUnknown _) = do
739check' val u@(TUnknown _) = do
686 val'@(TypedValue _ _ ty) <- infer val
740 val'@(TypedValue _ _ ty) <- infer val
687 -- Don't unify an unknown with an inferred polytype
741 -- Don't unify an unknown with an inferred polytype
688 ty' <- replaceAllVarsWithUnknowns ty
742 ty' <- replaceAllVarsWithUnknowns ty
689 ty' =?= u
743 ty' =?= u
690− return val'
744+ return $ TypedValue True val' ty'
691−check' v@(NumericLiteral _) t | t == tyNumber = return v
745+check' v@(NumericLiteral _) t | t == tyNumber =
746+ return $ TypedValue True v t
692−check' v@(StringLiteral _) t | t == tyString = return v
747+check' v@(StringLiteral _) t | t == tyString =
748+ return $ TypedValue True v t
693−check' v@(BooleanLiteral _) t | t == tyBoolean = return v
749+check' v@(BooleanLiteral _) t | t == tyBoolean =
750+ return $ TypedValue True v t
694−check' (ArrayLiteral vals) (TypeApp a ty) | a == tyArray = ArrayLiteral <$> forM vals (\val -> check val ty)
751+check' (ArrayLiteral vals) t@(TypeApp a ty) | a == tyArray = do
752+ arr <- ArrayLiteral <$> forM vals (\val -> check val ty)
753+ return $ TypedValue True arr t
695−check' (Abs arg ret) (TypeApp (TypeApp t argTy) retTy) | t == tyFunction = do
754+check' (Abs arg ret) ty@(TypeApp (TypeApp t argTy) retTy) | t == tyFunction = do
696 Just moduleName <- checkCurrentModule <$> get
755 Just moduleName <- checkCurrentModule <$> get
697 ret' <- bindLocalVariables moduleName [(arg, argTy)] $ check ret retTy
756 ret' <- bindLocalVariables moduleName [(arg, argTy)] $ check ret retTy
698− return $ Abs arg ret'
757+ return $ TypedValue True (Abs arg ret') ty
699check' (App f arg) ret = do
758check' (App f arg) ret = do
700 f'@(TypedValue _ _ ft) <- infer f
759 f'@(TypedValue _ _ ft) <- infer f
701− app <- checkFunctionApplication f' ft arg ret
760+ (ret', app) <- checkFunctionApplication f' ft arg
761+ subsumes Nothing ret' ret
702− return $ app
762+ return $ TypedValue True app ret
703check' v@(Var var) ty = do
763check' v@(Var var) ty = do
704 Just moduleName <- checkCurrentModule <$> get
764 Just moduleName <- checkCurrentModule <$> get
705− ty1 <- lookupVariable moduleName var
765+ repl <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
706− repl <- replaceAllTypeSynonyms ty1
707− ty' <- replaceAllTypeSynonyms ty
766+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
708 v' <- subsumes (Just v) repl ty'
767 v' <- subsumes (Just v) repl ty'
709 case v' of
768 case v' of
710 Nothing -> throwError "Unable to check type subsumption"
769 Nothing -> throwError "Unable to check type subsumption"
711− Just v'' -> return v''
770+ Just v'' -> return $ TypedValue True v'' ty'
712check' (TypedValue checkType val ty1) ty2 = do
771check' (TypedValue checkType val ty1) ty2 = do
713 Just moduleName <- checkCurrentModule <$> get
772 Just moduleName <- checkCurrentModule <$> get
714 kind <- liftCheck $ kindOf moduleName ty1
773 kind <- liftCheck $ kindOf moduleName ty1
@@ -718,22 +777,22 @@ check' (TypedValue checkType val ty1) ty2 = do
718 Nothing -> throwError "Unable to check type subsumption"
777 Nothing -> throwError "Unable to check type subsumption"
719 Just val'' -> do
778 Just val'' -> do
720 val''' <- if checkType then check val'' ty1 else return val''
779 val''' <- if checkType then check val'' ty1 else return val''
721− return $ TypedValue True val''' ty1
780+ return $ TypedValue checkType (TypedValue True val''' ty1) ty2
722check' (Case vals binders) ret = do
781check' (Case vals binders) ret = do
723 vals' <- mapM infer vals
782 vals' <- mapM infer vals
724 let ts = map (\(TypedValue _ _ t) -> t) vals'
783 let ts = map (\(TypedValue _ _ t) -> t) vals'
725 binders' <- checkBinders ts ret binders
784 binders' <- checkBinders ts ret binders
726− return $ Case vals' binders'
785+ return $ TypedValue True (Case vals' binders') ret
727check' (IfThenElse cond th el) ty = do
786check' (IfThenElse cond th el) ty = do
728 cond' <- check cond tyBoolean
787 cond' <- check cond tyBoolean
729 th' <- check th ty
788 th' <- check th ty
730 el' <- check el ty
789 el' <- check el ty
731− return $ IfThenElse cond' th' el'
790+ return $ TypedValue True (IfThenElse cond' th' el') ty
732−check' (ObjectLiteral ps) (Object row) = do
791+check' (ObjectLiteral ps) t@(Object row) = do
733 ensureNoDuplicateProperties ps
792 ensureNoDuplicateProperties ps
734 ps' <- checkProperties ps row False
793 ps' <- checkProperties ps row False
735− return $ ObjectLiteral ps'
794+ return $ TypedValue True (ObjectLiteral ps') t
736−check' (ObjectUpdate obj ps) (Object row) = do
795+check' (ObjectUpdate obj ps) t@(Object row) = do
737 ensureNoDuplicateProperties ps
796 ensureNoDuplicateProperties ps
738 us <- zip (map fst ps) <$> replicateM (length ps) fresh
797 us <- zip (map fst ps) <$> replicateM (length ps) fresh
739 let (propsToCheck, rest) = rowToList row
798 let (propsToCheck, rest) = rowToList row
@@ -741,27 +800,24 @@ check' (ObjectUpdate obj ps) (Object row) = do
741 remainingProps = filter (\(p, _) -> p `notElem` propsToRemove) propsToCheck
800 remainingProps = filter (\(p, _) -> p `notElem` propsToRemove) propsToCheck
742 obj' <- check obj (Object (rowFromList (us ++ remainingProps, rest)))
801 obj' <- check obj (Object (rowFromList (us ++ remainingProps, rest)))
743 ps' <- checkProperties ps row True
802 ps' <- checkProperties ps row True
744− return $ ObjectUpdate obj' ps'
803+ return $ TypedValue True (ObjectUpdate obj' ps') t
745check' (Accessor prop val) ty = do
804check' (Accessor prop val) ty = do
746 rest <- fresh
805 rest <- fresh
747 val' <- check val (Object (RCons prop ty rest))
806 val' <- check val (Object (RCons prop ty rest))
748− return $ Accessor prop val'
807+ return $ TypedValue True (Accessor prop val') ty
749check' (Block ss) ret = do
808check' (Block ss) ret = do
750 (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
809 (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
751 guardWith "Block is missing a return statement" allCodePathsReturn
810 guardWith "Block is missing a return statement" allCodePathsReturn
752− return $ Block ss'
811+ return $ TypedValue True (Block ss') ret
753check' (Constructor c) ty = do
812check' (Constructor c) ty = do
754 env <- getEnv
813 env <- getEnv
755 Just moduleName <- checkCurrentModule <$> get
814 Just moduleName <- checkCurrentModule <$> get
756 case M.lookup (qualify moduleName c) (dataConstructors env) of
815 case M.lookup (qualify moduleName c) (dataConstructors env) of
757 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
816 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
758 Just (ty1, _) -> do
817 Just (ty1, _) -> do
759− repl <- replaceAllTypeSynonyms ty1
818+ repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
760 _ <- subsumes Nothing repl ty
819 _ <- subsumes Nothing repl ty
761− return $ Constructor c
820+ return $ TypedValue True (Constructor c) ty
762−check' val (SaturatedTypeSynonym name args) = do
763− ty <- expandTypeSynonym name args
764− check val ty
765check' val ty = throwError $ prettyPrintValue val ++ " does not have type " ++ prettyPrintType ty
821check' val ty = throwError $ prettyPrintValue val ++ " does not have type " ++ prettyPrintType ty
766
822
767-- |
823-- |
@@ -774,7 +830,7 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
774 go [] [] REmpty = return []
830 go [] [] REmpty = return []
775 go [] [] u@(TUnknown _) = do u =?= REmpty
831 go [] [] u@(TUnknown _) = do u =?= REmpty
776 return []
832 return []
777− go [] [] (Skolem _) | lax = return []
833+ go [] [] (Skolem _ _) | lax = return []
778 go [] ((p, _): _) _ | lax = return []
834 go [] ((p, _): _) _ | lax = return []
779 | otherwise = throwError $ prettyPrintValue (ObjectLiteral ps) ++ " does not have property " ++ p
835 | otherwise = throwError $ prettyPrintValue (ObjectLiteral ps) ++ " does not have property " ++ p
780 go ((p,_):_) [] REmpty = throwError $ "Property " ++ p ++ " is not present in closed object type " ++ prettyPrintRow row
836 go ((p,_):_) [] REmpty = throwError $ "Property " ++ p ++ " is not present in closed object type " ++ prettyPrintRow row
@@ -801,8 +857,8 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
801-- |
857-- |
802-- Check the type of a function application, rethrowing errors to provide a better error message
858-- Check the type of a function application, rethrowing errors to provide a better error message
803--
859--
804−checkFunctionApplication :: Value -> Type -> Value -> Type -> UnifyT Type Check Value
860+checkFunctionApplication :: Value -> Type -> Value -> UnifyT Type Check (Type, Value)
805−checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionApplication' fn fnTy arg ret
861+checkFunctionApplication fn fnTy arg = rethrow errorMessage $ checkFunctionApplication' fn fnTy arg
806 where
862 where
807 errorMessage msg = "Error applying function of type "
863 errorMessage msg = "Error applying function of type "
808 ++ prettyPrintType fnTy
864 ++ prettyPrintType fnTy
@@ -812,34 +868,33 @@ checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionA
812-- |
868-- |
813-- Check the type of a function application
869-- Check the type of a function application
814--
870--
815−checkFunctionApplication' :: Value -> Type -> Value -> Type -> UnifyT Type Check Value
871+checkFunctionApplication' :: Value -> Type -> Value -> UnifyT Type Check (Type, Value)
816−checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg ret = do
872+checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg = do
817 tyFunction' =?= tyFunction
873 tyFunction' =?= tyFunction
818 arg' <- check arg argTy
874 arg' <- check arg argTy
819− _ <- subsumes Nothing retTy ret
820− return $ App fn arg'
875+ return (retTy, App fn arg')
821−checkFunctionApplication' fn (ForAll ident ty) arg ret = do
876+checkFunctionApplication' fn (ForAll ident ty _) arg = do
822 replaced <- replaceVarWithUnknown ident ty
877 replaced <- replaceVarWithUnknown ident ty
823− checkFunctionApplication fn replaced arg ret
878+ checkFunctionApplication fn replaced arg
824−checkFunctionApplication' fn u@(TUnknown _) arg ret = do
879+checkFunctionApplication' fn u@(TUnknown _) arg = do
825 arg' <- do
880 arg' <- do
826 TypedValue _ v t <- infer arg
881 TypedValue _ v t <- infer arg
827 TypedValue True v <$> replaceAllVarsWithUnknowns t
882 TypedValue True v <$> replaceAllVarsWithUnknowns t
828 let ty = (\(TypedValue _ _ t) -> t) arg'
883 let ty = (\(TypedValue _ _ t) -> t) arg'
884+ ret <- fresh
829 u =?= function ty ret
885 u =?= function ty ret
830− return $ App fn arg'
886+ return (ret, App fn arg')
831−checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
887+checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg = do
832− ty <- expandTypeSynonym name tyArgs
888+ ty <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
833− checkFunctionApplication fn ty arg ret
889+ checkFunctionApplication fn ty arg
834−checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
890+checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg = do
835 env <- getEnv
891 env <- getEnv
836 dicts <- getTypeClassDictionaries
892 dicts <- getTypeClassDictionaries
837 Just moduleName <- checkCurrentModule <$> get
893 Just moduleName <- checkCurrentModule <$> get
838− checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) fnTy arg ret
894+ checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) fnTy arg
839−checkFunctionApplication' _ fnTy arg ret = throwError $ "Applying a function of type "
895+checkFunctionApplication' _ fnTy arg = throwError $ "Cannot apply a function of type "
840 ++ prettyPrintType fnTy
896 ++ prettyPrintType fnTy
841− ++ " to argument(s) " ++ prettyPrintValue arg
897+ ++ " to argument " ++ prettyPrintValue arg
842− ++ " does not yield a value of type " ++ prettyPrintType ret ++ "."
843
898
844-- |
899-- |
845-- Check whether one type subsumes another, rethrowing errors to provide a better error message
900-- Check whether one type subsumes another, rethrowing errors to provide a better error message
@@ -857,18 +912,25 @@ subsumes val ty1 ty2 = rethrow errorMessage $ subsumes' val ty1 ty2
857-- Check whether one type subsumes another
912-- Check whether one type subsumes another
858--
913--
859subsumes' :: Maybe Value -> Type -> Type -> UnifyT Type Check (Maybe Value)
914subsumes' :: Maybe Value -> Type -> Type -> UnifyT Type Check (Maybe Value)
860−subsumes' val (ForAll ident ty1) ty2 = do
915+subsumes' val (ForAll ident ty1 _) ty2 = do
861 replaced <- replaceVarWithUnknown ident ty1
916 replaced <- replaceVarWithUnknown ident ty1
862 subsumes val replaced ty2
917 subsumes val replaced ty2
918+subsumes' val ty1 (ForAll ident ty2 sco) =
919+ case sco of
920+ Just sco' -> do
921+ sko <- newSkolemConstant
922+ let sk = skolemize ident sko sco' ty2
923+ subsumes val ty1 sk
924+ Nothing -> throwError "Skolem variable scope is unspecified"
863subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
925subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
864 subsumes Nothing arg2 arg1
926 subsumes Nothing arg2 arg1
865 subsumes Nothing ret1 ret2
927 subsumes Nothing ret1 ret2
866 return val
928 return val
867subsumes' val (SaturatedTypeSynonym name tyArgs) ty2 = do
929subsumes' val (SaturatedTypeSynonym name tyArgs) ty2 = do
868− ty1 <- expandTypeSynonym name tyArgs
930+ ty1 <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
869 subsumes val ty1 ty2
931 subsumes val ty1 ty2
870subsumes' val ty1 (SaturatedTypeSynonym name tyArgs) = do
932subsumes' val ty1 (SaturatedTypeSynonym name tyArgs) = do
871− ty2 <- expandTypeSynonym name tyArgs
933+ ty2 <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
872 subsumes val ty1 ty2
934 subsumes val ty1 ty2
873subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
935subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
874 env <- getEnv
936 env <- getEnv
src/Language/PureScript/Types.hs+10−5
@@ -24,6 +24,11 @@ import Control.Monad.Unify
24
24
25import Language.PureScript.Names
25import Language.PureScript.Names
26
26
27+-- |
28+-- An identifier for the scope of a skolem variable
29+--
30+newtype SkolemScope = SkolemScope { runSkolemScope :: Int } deriving (Show, Eq, Ord, Data, Typeable)
31+
27-- |
32-- |
28-- The type of types
33-- The type of types
29--
34--
@@ -55,7 +60,7 @@ data Type
55 -- |
60 -- |
56 -- Forall quantifier
61 -- Forall quantifier
57 --
62 --
58− | ForAll String Type
63+ | ForAll String Type (Maybe SkolemScope)
59 -- |
64 -- |
60 -- A type with a set of type class constraints
65 -- A type with a set of type class constraints
61 --
66 --
@@ -63,7 +68,7 @@ data Type
63 -- |
68 -- |
64 -- A skolem constant
69 -- A skolem constant
65 --
70 --
66− | Skolem Int
71+ | Skolem Int SkolemScope
67 -- |
72 -- |
68 -- An empty row
73 -- An empty row
69 --
74 --
@@ -128,14 +133,14 @@ rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
128-- Check whether a type is a monotype
133-- Check whether a type is a monotype
129--
134--
130isMonoType :: Type -> Bool
135isMonoType :: Type -> Bool
131−isMonoType (ForAll _ _) = False
136+isMonoType (ForAll _ _ _) = False
132isMonoType ty = True
137isMonoType ty = True
133
138
134-- |
139-- |
135-- Universally quantify a type
140-- Universally quantify a type
136--
141--
137mkForAll :: [String] -> Type -> Type
142mkForAll :: [String] -> Type -> Type
138−mkForAll = flip . foldl . flip $ ForAll
143+mkForAll args ty = foldl (\t arg -> ForAll arg t Nothing) ty args
139
144
140-- |
145-- |
141-- The empty record type
146-- The empty record type
@@ -151,5 +156,5 @@ replaceTypeVars name t = everywhereBut (mkQ False isShadowed) (mkT replaceTypeVa
151 where
156 where
152 replaceTypeVar (TypeVar v) | v == name = t
157 replaceTypeVar (TypeVar v) | v == name = t
153 replaceTypeVar other = other
158 replaceTypeVar other = other
154− isShadowed (ForAll v _) | v == name = True
159+ isShadowed (ForAll v _ _) | v == name = True
155 isShadowed _ = False
160 isShadowed _ = False