git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' of https://github.com/garyb/purescript
commita621359c904cf15fd7a3a1e24e72bba3b9313fa4 authorGary Burgess <garyb@users.noreply.github.com> dateThu 6 Feb 2014, 20:48 (13 years ago) parent29fdee579ea6ef
19 files changed+1960−212
docgen/Main.hs+155 docs/source/blocks.rst+1−1 docs/source/prelude.rst+745−60 examples/failing/SkolemEscape2.purs+9 examples/passing/Do.purs−16 examples/passing/Eff.purs+3−3 examples/passing/Monad.purs+1−1 libraries/prelude/README.md+683 libraries/prelude/prelude.purs+153−9 libraries/prelude/tests/Eff.purs+16−6 libraries/prelude/updateDocs.sh+2 purescript.cabal+10−1 src/Language/PureScript/CodeGen/JS.hs+3−3 src/Language/PureScript/Pretty/Types.hs+3−3 src/Language/PureScript/Sugar/TypeClasses.hs+2−2 src/Language/PureScript/TypeChecker.hs+1−1 src/Language/PureScript/TypeChecker/Kinds.hs+1−1 src/Language/PureScript/TypeChecker/Types.hs+162−100 src/Language/PureScript/Types.hs+10−5
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 `
7373If-Then-Else Statements
7474-----------------------
7575
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::
7777
7878 collatz n = {
7979 var count = 0;
docs/source/prelude.rst+745−60
@@ -1,88 +1,773 @@
1−Prelude
2−=======
1+Module Documentation
2+====================
33
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
75--------------
86
9−=========== ============================================================ ===========================================
10−Name Type Description
11−=========== ============================================================ ===========================================
12−``id`` ``forall a. a -> a`` Identity function
13−``flip`` ``forall a b c. (a -> b -> c) -> b -> a -> c`` Flips the order of a function's arguments
14−``konst`` ``forall a b. a -> b -> a`` Defines a constant function
15−``(<|)`` ``forall a b c. (a -> b) -> (b -> c) -> a -> c`` Function composition
16−``(|>)`` ``forall a b c. (b -> c) -> (a -> b) -> a -> c`` Function composition
17−``($)`` ``forall a b. (a -> b) -> a -> b`` Function application
18−=========== ============================================================ ===========================================
19−
20−======= ===========================================
21−Name Description
22−======= ===========================================
23−Show Type class for types whose values can be
24− converted to strings
25−Monad Type class for type constructors which
26− support ``do`` notation
27−======= ===========================================
28−
29−String Module
7+Types
8+~~~~~
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
53+ id :: forall t. a t t
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+
148+ konst :: forall b. forall a. a -> b -> a
149+
150+ numAdd :: Prelude.Number -> Prelude.Number -> Prelude.Number
151+
152+ numAnd :: Prelude.Number -> Prelude.Number -> Prelude.Number
153+
154+ numComplement :: Prelude.Number -> Prelude.Number
155+
156+ numDiv :: Prelude.Number -> Prelude.Number -> Prelude.Number
157+
158+ numGreater :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
159+
160+ numGreaterEq :: Prelude.Number -> Prelude.Number -> Prelude.Boolean
161+
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+
194+Module Monoid
30195-------------
31196
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+~~~~~~~~~~~~~~~~~~~~
33211
34−Regex Module
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+
223+Module Monad
35224------------
36225
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
38241
39−Maybe Module
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+
256+Module Maybe
40257------------
41258
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+~~~~~~~~~~~~
43270
44−Either Module
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+
287+Module Either
45288-------------
46289
47−`TODO`
48−
49−Arrays Module
290+Types
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+
316+Module Arrays
50317-------------
51318
52−`TODO`
53−
54−Tuple Module
319+Types
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+
397+Module Tuple
55398------------
56399
57−`TODO`
58−
59−Eff Module
60−----------
400+Types
401+~~~~~
402+
403+::
404+
405+ type Tuple a b = { snd :: b, fst :: a }
406+
407+Type Classes
408+~~~~~~~~~~~~
61409
62−`TODO`
63−
64−Errors Module
410+Type Class Instances
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+
428+Module String
65429-------------
66430
67−`TODO`
68−
69−IORef Module
431+Types
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+
471+Module Regex
70472------------
71473
72−`TODO`
73−
74−Random Module
474+Types
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+
502+Module Global
75503-------------
76504
77−`TODO`
78−
79−ST Module
80−---------
505+Types
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+
545+Module Math
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
81595
82−`TODO`
83−
84−Trace Module
596+Module Eff
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+
716+Module Trace
85717------------
86718
87−`TODO`
88−
719+Types
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
4242 Just (do
4343 Just 1)
4444
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−
6145test9 = \_ -> (+) <$> Just 1 <*> Just 2
6246
6347module Main where
examples/passing/Eff.purs+3−3
@@ -10,10 +10,10 @@ test1 = catchError (\s -> ret 0) $ do
1010 trace "Testing"
1111 throwError "Error!"
1212
13−test2 = runPure $ runST $ do
13+test2 = runPure (runST (do
1414 ref <- newSTRef 0
1515 modifySTRef ref $ \n -> n + 1
16− readSTRef ref
16+ readSTRef ref))
1717
1818module Main where
1919
@@ -24,4 +24,4 @@ import TestEff
2424main = do
2525 n <- test1
2626 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
22
33 type Monad m = { ret :: forall a. a -> m a
44 , 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
6161 read "true" = true
6262 read _ = false
6363
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+
6484 class Monad m where
6585 ret :: forall a. a -> m a
6686 (>>=) :: forall a b. m a -> (a -> m b) -> m b
6787
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+
6895 infixl 5 *
6996 infixl 5 /
7097 infixl 5 %
@@ -326,6 +353,74 @@ module Prelude where
326353 \ };\
327354 \}" :: String -> String -> String
328355
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+
329424module Maybe where
330425
331426 import Prelude
@@ -408,9 +503,9 @@ module Arrays where
408503 \ };\
409504 \}" :: forall a. [a] -> [a] -> [a]
410505
411− foreign import join "function join(l) {\
412− \ return l.join();\
413− \}" :: [String] -> String
506+ foreign import joinS "function joinS(l) {\
507+ \ return l.join();\
508+ \}" :: [String] -> String
414509
415510 foreign import joinWith "function joinWith(l) {\
416511 \ return function (s) {\
@@ -467,6 +562,9 @@ module Arrays where
467562 (:) :: forall a. a -> [a] -> [a]
468563 (:) a = concat [a]
469564
565+ singleton :: forall a. a -> [a]
566+ singleton a = [a]
567+
470568 concatMap :: forall a b. [a] -> (a -> [b]) -> [b]
471569 concatMap [] f = []
472570 concatMap (a:as) f = f a `concat` concatMap as f
@@ -476,9 +574,9 @@ module Arrays where
476574 filter p (x:xs) | p x = x : filter p xs
477575 filter p (_:xs) = filter p xs
478576
479− empty :: forall a. [a] -> Boolean
480− empty [] = true
481− empty _ = false
577+ isEmpty :: forall a. [a] -> Boolean
578+ isEmpty [] = true
579+ isEmpty _ = false
482580
483581 range :: Number -> Number -> [Number]
484582 range lo hi = {
@@ -505,6 +603,14 @@ module Arrays where
505603 show [] = "[]"
506604 show (x:xs) = show x ++ " : " ++ show xs
507605
606+ instance Prelude.Monad [] where
607+ ret = singleton
608+ (>>=) = concatMap
609+
610+ instance Prelude.Alternative [] where
611+ empty = []
612+ (<|>) = concat
613+
508614module Tuple where
509615
510616 import Prelude
@@ -783,6 +889,46 @@ module Eff where
783889 ret = retEff
784890 (>>=) = bindEff
785891
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+
786932module Random where
787933
788934 import Eff
@@ -790,9 +936,7 @@ module Random where
790936 foreign import data Random :: !
791937
792938 foreign import random "function random() {\
793− \ return function() {\
794− \ return Math.random();\
795− \ };\
939+ \ return Math.random();\
796940 \}" :: forall e. Eff (random :: Random | e) Number
797941
798942module Errors where
libraries/prelude/tests/Eff.purs+16−6
@@ -6,11 +6,11 @@ import Errors
66import Trace
77import Global
88
9−test1 n = runPure $ catchError (\s -> ret 0) $ do
9+test1 n = runPure (catchError (\s -> ret 0) $ do
1010 case {} of
1111 _ | n > 10 -> do
1212 throwError "Error!"
13− _ -> ret n
13+ _ -> ret n)
1414
1515test2 = do
1616 trace "Hello World"
@@ -38,14 +38,24 @@ test6 s = do
3838import ST
3939
4040test7 _ = do
41− n <- runST $ do
41+ n <- runST (do
4242 r <- newSTRef 0
4343 modifySTRef r $ \n -> n + 1
44− readSTRef r
45− print $ n
44+ readSTRef r)
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
4656
4757module Main where
4858
4959import Tests
5060
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 @@
11name: purescript
2−version: 0.3.8.1
2+version: 0.3.9
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
@@ -86,6 +86,15 @@ executable psci
8686 other-modules:
8787 ghc-options: -Wall -O2
8888
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+
8998test-suite tests
9099 build-depends: base >=4 && <5, containers -any, directory -any,
91100 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 =
128128 where
129129 getFunctionArgumentType :: Type -> Maybe Type
130130 getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
131− getFunctionArgumentType (ForAll _ ty') = getFunctionArgumentType ty'
131+ getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
132132 getFunctionArgumentType _ = Nothing
133133 argumentCheck :: JS -> Type -> [JS]
134134 argumentCheck val t | t == tyNumber = [typeCheck val "number"]
@@ -141,7 +141,7 @@ runtimeTypeChecks arg ty =
141141 in
142142 typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (JSAccessor prop val) ty') pairs
143143 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'
145145 argumentCheck _ _ = []
146146 typeCheck :: JS -> String -> JS
147147 typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
@@ -253,7 +253,7 @@ isOnlyConstructor m e ctor =
253253 where
254254 numConstructors ty = length $ filter (\(ty1, _) -> ((==) `on` typeConstructor) ty ty1) $ M.elems $ dataConstructors e
255255 typeConstructor (TypeConstructor qual) = qualify m qual
256− typeConstructor (ForAll _ ty) = typeConstructor ty
256+ typeConstructor (ForAll _ ty _) = typeConstructor ty
257257 typeConstructor (TypeApp (TypeApp t _) ty) | t == tyFunction = typeConstructor ty
258258 typeConstructor (TypeApp ty _) = typeConstructor ty
259259 typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn
src/Language/PureScript/Pretty/Types.hs+3−3
@@ -36,10 +36,10 @@ typeLiterals = mkPattern match
3636 match (TypeApp arr ty) | arr == tyArray = Just $ "[" ++ prettyPrintType ty ++ "]"
3737 match (TypeConstructor ctor) = Just $ show ctor
3838 match (TUnknown (Unknown u)) = Just $ 'u' : show u
39− match (Skolem s) = Just $ 's' : show s
39+ match (Skolem s _) = Just $ 's' : show s
4040 match (ConstrainedType deps ty) = Just $ "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ prettyPrintType ty' ++ ")") deps) ++ ") => " ++ prettyPrintType ty
4141 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
4343 match REmpty = Just $ prettyPrintRow REmpty
4444 match row@(RCons _ _ _) = Just $ prettyPrintRow row
4545 match _ = Nothing
@@ -56,7 +56,7 @@ prettyPrintRow = (\(tys, rest) -> intercalate ", " (map (uncurry nameAndTypeToPs
5656 tailToPs REmpty = ""
5757 tailToPs (TUnknown (Unknown u)) = " | u" ++ show u
5858 tailToPs (TypeVar var) = " | " ++ var
59− tailToPs (Skolem s) = " | s" ++ show s
59+ tailToPs (Skolem s _) = " | s" ++ show s
6060 tailToPs _ = error "Invalid row tail"
6161 toList :: [(String, Type)] -> Type -> ([(String, Type)], Type)
6262 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
7474typeClassMemberToDictionaryAccessor name arg (TypeDeclaration ident ty) =
7575 ExternDeclaration TypeClassAccessorImport ident
7676 (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)
7878typeClassMemberToDictionaryAccessor _ _ _ = error "Invalid declaration in type class definition"
7979
8080typeInstanceDictionaryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> [Declaration] -> Desugar Declaration
@@ -120,7 +120,7 @@ qualifiedToString mn (Qualified Nothing pn) = qualifiedToString mn (Qualified (J
120120qualifiedToString _ (Qualified (Just (ModuleName mn)) pn) = runProperName mn ++ "_" ++ runProperName pn
121121
122122quantify :: Type -> Type
123−quantify ty' = foldr ForAll ty' tyVars
123+quantify ty' = foldr (\arg t -> ForAll arg t Nothing) ty' tyVars
124124 where
125125 tyVars = nub $ everything (++) (mkQ [] collect) ty'
126126 collect (TypeVar v) = [v]
src/Language/PureScript/TypeChecker.hs+1−1
@@ -230,7 +230,7 @@ typeCheckAll currentModule (d@(ImportDeclaration moduleName idents) : rest) = do
230230 addTypeClassDictionaries [tcd { tcdName = (Qualified (Just currentModule) ident), tcdType = TCDAlias (tcdName tcd) }]
231231 constructs (TypeConstructor (Qualified (Just mn) pn')) pn
232232 = mn == moduleName && pn' == pn
233− constructs (ForAll _ ty) pn = ty `constructs` pn
233+ constructs (ForAll _ ty _) pn = ty `constructs` pn
234234 constructs (TypeApp (TypeApp t _) ty) pn | t == tyFunction = ty `constructs` pn
235235 constructs (TypeApp ty _) pn = ty `constructs` pn
236236 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
142142 k2 <- infer t2
143143 k1 =?= FunKind k2 k0
144144 return k0
145−infer (ForAll ident ty) = do
145+infer (ForAll ident ty _) = do
146146 k <- fresh
147147 Just moduleName <- checkCurrentModule <$> get
148148 bindLocalTypeVariables moduleName [(ProperName ident, k)] $ infer ty
src/Language/PureScript/TypeChecker/Types.hs+162−100
@@ -45,7 +45,8 @@ import Data.List
4545import Data.Maybe (maybeToList, isNothing, isJust, fromMaybe)
4646import qualified Data.Data as D
4747import Data.Generics
48− (mkM, everywhereM, everything, mkT, something, everywhere, mkQ)
48+ (everythingWithContext, mkM, everywhereM, everything, mkT,
49+ something, everywhere, mkQ)
4950
5051import Language.PureScript.Values
5152import Language.PureScript.Types
@@ -66,6 +67,7 @@ import Control.Arrow (Arrow(..))
6667
6768import qualified Data.Map as M
6869import Data.Function (on)
70+import Debug.Trace (trace)
6971
7072instance Partial Type where
7173 unknown = TUnknown
@@ -86,17 +88,23 @@ unifyTypes t1 t2 = rethrow (\e -> "Error unifying type " ++ prettyPrintType t1 +
8688 unifyTypes' (TUnknown u) t = u =:= t
8789 unifyTypes' t (TUnknown u) = u =:= t
8890 unifyTypes' (SaturatedTypeSynonym name args) ty = do
89− ty1 <- expandTypeSynonym name args
91+ ty1 <- introduceSkolemScope <=< expandTypeSynonym name $ args
9092 ty1 `unifyTypes` ty
9193 unifyTypes' ty s@(SaturatedTypeSynonym _ _) = s `unifyTypes` ty
92− unifyTypes' (ForAll ident1 ty1) (ForAll ident2 ty2) = do
93− sk <- skolemize ident1 ty1
94− replaced <- replaceVarWithUnknown ident2 ty2
95− sk `unifyTypes` replaced
96− unifyTypes' (ForAll ident ty1) ty2 = do
97− sk <- skolemize ident ty1
94+ unifyTypes' (ForAll ident1 ty1 sc1) (ForAll ident2 ty2 sc2) =
95+ case (sc1, sc2) of
96+ (Just sc1', Just sc2') -> do
97+ sko <- newSkolemConstant
98+ let sk1 = skolemize ident1 sko sc1' ty1
99+ let sk2 = skolemize ident2 sko sc2' ty2
100+ sk1 `unifyTypes` sk2
101+ _ -> throwError (prettyPrintType ty1)
102+ unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
103+ sko <- newSkolemConstant
104+ let sk = skolemize ident sko sc ty1
98105 sk `unifyTypes` ty2
99− unifyTypes' ty f@(ForAll _ _) = f `unifyTypes` ty
106+ unifyTypes' (ForAll _ _ _) _ = throwError "Skolem variable scope is unspecified"
107+ unifyTypes' ty f@(ForAll _ _ _) = f `unifyTypes` ty
100108 unifyTypes' (Object row1) (Object row2) = row1 =?= row2
101109 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
102110 unifyTypes' (TypeConstructor c1) (TypeConstructor c2) = do
@@ -106,7 +114,7 @@ unifyTypes t1 t2 = rethrow (\e -> "Error unifying type " ++ prettyPrintType t1 +
106114 unifyTypes' (TypeApp t3 t4) (TypeApp t5 t6) = do
107115 t3 `unifyTypes` t5
108116 t4 `unifyTypes` t6
109− unifyTypes' (Skolem s1) (Skolem s2) | s1 == s2 = return ()
117+ unifyTypes' (Skolem s1 _) (Skolem s2 _) | s1 == s2 = return ()
110118 unifyTypes' r1@(RCons _ _ _) r2 = unifyRows r1 r2
111119 unifyTypes' r1 r2@(RCons _ _ _) = unifyRows r1 r2
112120 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
@@ -143,7 +151,7 @@ unifyRows r1 r2 =
143151 unifyRows' row r others u'
144152 unifyRows' [] REmpty [] REmpty = return ()
145153 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 ()
147155 unifyRows' sd3 r3 sd4 r4 = throwError $ "Cannot unify " ++ prettyPrintRow (rowFromList (sd3, r3)) ++ " with " ++ prettyPrintRow (rowFromList (sd4, r4)) ++ "."
148156
149157-- |
@@ -171,22 +179,24 @@ typesOf moduleName vals = do
171179 (ident, (val, Just (ty, checkType))) -> do
172180 kind <- liftCheck $ kindOf moduleName ty
173181 guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
174− ty' <- replaceAllTypeSynonyms ty
175− val' <- bindNames dict $ if checkType then check val ty' else return val
182+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
183+ val' <- bindNames dict $ if checkType
184+ then TypedValue True <$> check val ty' <*> pure ty'
185+ else return (TypedValue False val ty')
176186 return (ident, (val', ty'))
177187 (ident, (val, Nothing)) -> do
178188 TypedValue _ val' ty <- bindNames dict $ infer val
179189 ty =?= fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
180− return (ident, (val', ty))
190+ return (ident, (TypedValue True val' ty, ty))
181191 when (moduleName == ModuleName (ProperName "Main") && fst e == Ident "main") $ do
182192 [eff, a] <- replicateM 2 fresh
183193 ty =?= TypeApp (TypeApp (TypeConstructor (Qualified (Just (ModuleName (ProperName "Eff"))) (ProperName "Eff"))) eff) a
184194 escapeCheck val ty
185195 return triple
186− forM_ tys $ skolemEscapeCheck . snd . snd
187196 forM tys $ \(ident, (val, ty)) -> do
188197 val' <- replaceTypeClassDictionaries moduleName val
189− return (ident, (overTypes (desaturateAllTypeSynonyms . setifyAll) $ val'
198+ rethrow (("Error in " ++ show ident ++ ": \n") ++) $ skolemEscapeCheck val'
199+ return $ (ident, (overTypes (desaturateAllTypeSynonyms . setifyAll) $ val'
190200 , varIfUnknown . desaturateAllTypeSynonyms . setifyAll $ ty))
191201 where
192202 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
238248 return $ Just dict
239249 mkDictionary :: Qualified Ident -> Maybe [Value] -> Value
240250 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
242252 filterModule :: TypeClassDictionaryInScope -> Bool
243253 filterModule (TypeClassDictionaryInScope { tcdName = Qualified (Just mn) _ }) | mn == moduleName = True
244254 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
@@ -252,7 +262,9 @@ entails moduleName context goal@(className, ty) = do
252262-- and return a substitution from type variables to types which makes the type heads unify.
253263--
254264typeHeadsAreEqual :: 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)]
256268typeHeadsAreEqual m e (TypeConstructor c1) (TypeConstructor c2) | typeConstructorsAreEqual e m c1 c2 = Just []
257269typeHeadsAreEqual m e (TypeApp h1 (TypeVar v)) (TypeApp h2 arg) = (:) (v, arg) <$> typeHeadsAreEqual m e h1 h2
258270typeHeadsAreEqual m e t1@(TypeApp _ _) t2@(TypeApp _ (TypeVar _)) = typeHeadsAreEqual m e t2 t1
@@ -268,7 +280,7 @@ escapeCheck value ty = do
268280 let allUnknowns = findAllTypes value
269281 forM_ allUnknowns $ \t -> do
270282 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
272284
273285-- |
274286-- Find all type annotations occuring inside a value
@@ -282,14 +294,31 @@ findAllTypes = everything (++) (mkQ [] go)
282294-- |
283295-- Ensure skolem variables do not escape their scope
284296--
285−skolemEscapeCheck :: Type -> Check ()
286−skolemEscapeCheck ty =
287− case something (mkQ Nothing findSkolems) ty of
288− Nothing -> return ()
289− Just _ -> throwError $ "Skolem variables cannot escape. Consider adding a type signature."
297+skolemEscapeCheck :: Value -> Check ()
298+skolemEscapeCheck (TypedValue False _ _) = return ()
299+skolemEscapeCheck root@(TypedValue _ _ _) =
300+ case everythingWithContext [] (++) (mkQ ((,) []) go) root of
301+ [] -> return ()
302+ ((binding, val) : _) -> throwError $ "Rigid/skolem type variable bound by " ++ maybe "<unknown>" prettyPrintValue binding ++ " has escaped at " ++ prettyPrintValue val
290303 where
291− findSkolems (Skolem _) = return ()
292− findSkolems _ = mzero
304+ go :: Value -> [(SkolemScope, Value)] -> ([(Maybe Value, Value)], [(SkolemScope, Value)])
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
293322
294323-- |
295324-- Ensure a row contains no duplicate labels
@@ -326,7 +355,7 @@ replaceAllTypeVars = foldl' (\f (name, ty) -> replaceTypeVars name ty . f) id
326355-- Replace named type variables with new unification variables
327356--
328357replaceAllVarsWithUnknowns :: Type -> UnifyT Type Check Type
329−replaceAllVarsWithUnknowns (ForAll ident ty) = replaceVarWithUnknown ident ty >>= replaceAllVarsWithUnknowns
358+replaceAllVarsWithUnknowns (ForAll ident ty _) = replaceVarWithUnknown ident ty >>= replaceAllVarsWithUnknowns
330359replaceAllVarsWithUnknowns ty = return ty
331360
332361-- |
@@ -404,7 +433,8 @@ infer' (ObjectUpdate o ps) = do
404433 newVals <- zipWith (\(name, _) t -> (name, t)) ps <$> mapM (infer . snd) ps
405434 let newTys = map (\(name, TypedValue _ _ ty) -> (name, ty)) newVals
406435 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
408438 return $ TypedValue True (ObjectUpdate o' newVals) $ Object $ rowFromList (newTys, row)
409439infer' (Accessor prop val) = do
410440 typed@(TypedValue _ _ objTy) <- infer val
@@ -424,19 +454,17 @@ infer' (Abs arg ret) = do
424454 return $ TypedValue True (Abs arg body) $ function ty bodyTy
425455infer' (App f arg) = do
426456 f'@(TypedValue _ _ ft) <- infer f
427− ret <- fresh
428− app <- checkFunctionApplication f' ft arg ret
457+ (ret, app) <- checkFunctionApplication f' ft arg
429458 return $ TypedValue True app ret
430459infer' (Var var) = do
431460 Just moduleName <- checkCurrentModule <$> get
432− ty <- lookupVariable moduleName var
433− ty' <- replaceAllTypeSynonyms ty
434− case ty' of
461+ ty <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
462+ case ty of
435463 ConstrainedType constraints _ -> do
436464 env <- getEnv
437465 dicts <- getTypeClassDictionaries
438− return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty'
439− _ -> return $ TypedValue True (Var var) ty'
466+ return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) ty
467+ _ -> return $ TypedValue True (Var var) ty
440468infer' (Block ss) = do
441469 ret <- fresh
442470 (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
@@ -447,7 +475,7 @@ infer' v@(Constructor c) = do
447475 Just moduleName <- checkCurrentModule <$> get
448476 case M.lookup (qualify moduleName c) (dataConstructors env) of
449477 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
450− Just (ty, _) -> do ty' <- replaceAllTypeSynonyms ty
478+ Just (ty, _) -> do ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
451479 return $ TypedValue True v ty'
452480infer' (Case vals binders) = do
453481 ts <- mapM infer vals
@@ -464,9 +492,9 @@ infer' (TypedValue checkType val ty) = do
464492 Just moduleName <- checkCurrentModule <$> get
465493 kind <- liftCheck $ kindOf moduleName ty
466494 guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
467− ty' <- replaceAllTypeSynonyms ty
495+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
468496 val' <- if checkType then check val ty' else return val
469− return $ TypedValue True val' ty
497+ return $ TypedValue True val' ty'
470498infer' _ = error "Invalid argument to infer"
471499
472500-- |
@@ -477,9 +505,9 @@ inferProperty (Object row) prop = do
477505 let (props, _) = rowToList row
478506 return $ lookup prop props
479507inferProperty (SaturatedTypeSynonym name args) prop = do
480− replaced <- expandTypeSynonym name args
508+ replaced <- introduceSkolemScope <=< expandTypeSynonym name $ args
481509 inferProperty replaced prop
482−inferProperty (ForAll ident ty) prop = do
510+inferProperty (ForAll ident ty _) prop = do
483511 replaced <- replaceVarWithUnknown ident ty
484512 inferProperty replaced prop
485513inferProperty _ _ = return Nothing
@@ -551,7 +579,7 @@ checkBinders nvals ret ((binders, grd, val):bs) = do
551579 Just moduleName <- checkCurrentModule <$> get
552580 m1 <- M.unions <$> zipWithM inferBinder nvals binders
553581 r <- bindLocalVariables moduleName (M.toList m1) $ do
554− val' <- check val ret
582+ val' <- TypedValue True <$> check val ret <*> pure ret
555583 case grd of
556584 Nothing -> return (binders, Nothing, val')
557585 Just g -> do
@@ -602,7 +630,7 @@ checkStatement mass ret (For ident start end inner) = do
602630 return (allCodePathsReturn, mass, For ident start' end' inner')
603631checkStatement mass ret (Return val) = do
604632 val' <- check val ret
605− return (True, mass, Return val')
633+ return (True, mass, Return (TypedValue True val' ret))
606634
607635-- |
608636-- Check the type of an if-then-else statement
@@ -642,13 +670,32 @@ checkBlock mass ret (s:ss) = do
642670 (b, m, ss'') <- checkBlock mass1 ret ss'
643671 return (b, m, s':ss'')
644672
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+
645685-- |
646686-- Skolemize a type variable by replacing its instances with fresh skolem constants
647687--
648−skolemize :: String -> Type -> UnifyT Type Check Type
649−skolemize ident ty = do
650− tsk <- Skolem . runUnknown <$> fresh'
651− return $ replaceTypeVars ident tsk ty
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+--
694+introduceSkolemScope :: Type -> UnifyT Type Check Type
695+introduceSkolemScope = everywhereM (mkM go)
696+ where
697+ go (ForAll ident ty Nothing) = ForAll ident ty <$> (Just <$> newSkolemScope)
698+ go other = return other
652699
653700-- |
654701-- 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
668715-- Check the type of a value
669716--
670717check' :: Value -> Type -> UnifyT Type Check Value
671−check' val (ForAll idents ty) = do
672− sk <- skolemize idents ty
673− check val sk
674−check' val (ConstrainedType constraints ty) = do
718+check' val t@(ForAll ident ty _) = do
719+ scope <- newSkolemScope
720+ sko <- newSkolemConstant
721+ let sk = skolemize ident sko scope ty
722+ val' <- check val sk
723+ return $ TypedValue True val' (ForAll ident ty (Just scope))
724+check' val t@(ConstrainedType constraints ty) = do
675725 env <- getEnv
676726 Just moduleName <- checkCurrentModule <$> get
677727 dictNames <- flip mapM constraints $ \(Qualified _ (ProperName className), _) -> do
@@ -681,34 +731,43 @@ check' val (ConstrainedType constraints ty) = do
681731 TypeClassDictionaryInScope name className instanceTy Nothing TCDRegular) (map (Qualified Nothing) dictNames)
682732 (qualifyAllUnqualifiedNames moduleName env constraints)) $
683733 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
685739check' val u@(TUnknown _) = do
686740 val'@(TypedValue _ _ ty) <- infer val
687741 -- Don't unify an unknown with an inferred polytype
688742 ty' <- replaceAllVarsWithUnknowns ty
689743 ty' =?= u
690− return val'
691−check' v@(NumericLiteral _) t | t == tyNumber = return v
692−check' v@(StringLiteral _) t | t == tyString = return v
693−check' v@(BooleanLiteral _) t | t == tyBoolean = return v
694−check' (ArrayLiteral vals) (TypeApp a ty) | a == tyArray = ArrayLiteral <$> forM vals (\val -> check val ty)
695−check' (Abs arg ret) (TypeApp (TypeApp t argTy) retTy) | t == tyFunction = do
744+ return $ TypedValue True val' ty'
745+check' v@(NumericLiteral _) t | t == tyNumber =
746+ return $ TypedValue True v t
747+check' v@(StringLiteral _) t | t == tyString =
748+ return $ TypedValue True v t
749+check' v@(BooleanLiteral _) t | t == tyBoolean =
750+ return $ TypedValue True v t
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
754+check' (Abs arg ret) ty@(TypeApp (TypeApp t argTy) retTy) | t == tyFunction = do
696755 Just moduleName <- checkCurrentModule <$> get
697756 ret' <- bindLocalVariables moduleName [(arg, argTy)] $ check ret retTy
698− return $ Abs arg ret'
757+ return $ TypedValue True (Abs arg ret') ty
699758check' (App f arg) ret = do
700759 f'@(TypedValue _ _ ft) <- infer f
701− app <- checkFunctionApplication f' ft arg ret
702− return $ app
760+ (ret', app) <- checkFunctionApplication f' ft arg
761+ subsumes Nothing ret' ret
762+ return $ TypedValue True app ret
703763check' v@(Var var) ty = do
704764 Just moduleName <- checkCurrentModule <$> get
705− ty1 <- lookupVariable moduleName var
706− repl <- replaceAllTypeSynonyms ty1
707− ty' <- replaceAllTypeSynonyms ty
765+ repl <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
766+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
708767 v' <- subsumes (Just v) repl ty'
709768 case v' of
710769 Nothing -> throwError "Unable to check type subsumption"
711− Just v'' -> return v''
770+ Just v'' -> return $ TypedValue True v'' ty'
712771check' (TypedValue checkType val ty1) ty2 = do
713772 Just moduleName <- checkCurrentModule <$> get
714773 kind <- liftCheck $ kindOf moduleName ty1
@@ -718,22 +777,22 @@ check' (TypedValue checkType val ty1) ty2 = do
718777 Nothing -> throwError "Unable to check type subsumption"
719778 Just val'' -> do
720779 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
722781check' (Case vals binders) ret = do
723782 vals' <- mapM infer vals
724783 let ts = map (\(TypedValue _ _ t) -> t) vals'
725784 binders' <- checkBinders ts ret binders
726− return $ Case vals' binders'
785+ return $ TypedValue True (Case vals' binders') ret
727786check' (IfThenElse cond th el) ty = do
728787 cond' <- check cond tyBoolean
729788 th' <- check th ty
730789 el' <- check el ty
731− return $ IfThenElse cond' th' el'
732−check' (ObjectLiteral ps) (Object row) = do
790+ return $ TypedValue True (IfThenElse cond' th' el') ty
791+check' (ObjectLiteral ps) t@(Object row) = do
733792 ensureNoDuplicateProperties ps
734793 ps' <- checkProperties ps row False
735− return $ ObjectLiteral ps'
736−check' (ObjectUpdate obj ps) (Object row) = do
794+ return $ TypedValue True (ObjectLiteral ps') t
795+check' (ObjectUpdate obj ps) t@(Object row) = do
737796 ensureNoDuplicateProperties ps
738797 us <- zip (map fst ps) <$> replicateM (length ps) fresh
739798 let (propsToCheck, rest) = rowToList row
@@ -741,27 +800,24 @@ check' (ObjectUpdate obj ps) (Object row) = do
741800 remainingProps = filter (\(p, _) -> p `notElem` propsToRemove) propsToCheck
742801 obj' <- check obj (Object (rowFromList (us ++ remainingProps, rest)))
743802 ps' <- checkProperties ps row True
744− return $ ObjectUpdate obj' ps'
803+ return $ TypedValue True (ObjectUpdate obj' ps') t
745804check' (Accessor prop val) ty = do
746805 rest <- fresh
747806 val' <- check val (Object (RCons prop ty rest))
748− return $ Accessor prop val'
807+ return $ TypedValue True (Accessor prop val') ty
749808check' (Block ss) ret = do
750809 (allCodePathsReturn, _, ss') <- checkBlock M.empty ret ss
751810 guardWith "Block is missing a return statement" allCodePathsReturn
752− return $ Block ss'
811+ return $ TypedValue True (Block ss') ret
753812check' (Constructor c) ty = do
754813 env <- getEnv
755814 Just moduleName <- checkCurrentModule <$> get
756815 case M.lookup (qualify moduleName c) (dataConstructors env) of
757816 Nothing -> throwError $ "Constructor " ++ show c ++ " is undefined"
758817 Just (ty1, _) -> do
759− repl <- replaceAllTypeSynonyms ty1
818+ repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
760819 _ <- subsumes Nothing repl ty
761− return $ Constructor c
762−check' val (SaturatedTypeSynonym name args) = do
763− ty <- expandTypeSynonym name args
764− check val ty
820+ return $ TypedValue True (Constructor c) ty
765821check' val ty = throwError $ prettyPrintValue val ++ " does not have type " ++ prettyPrintType ty
766822
767823-- |
@@ -774,7 +830,7 @@ checkProperties ps row lax = let (ts, r') = rowToList row in go ps ts r' where
774830 go [] [] REmpty = return []
775831 go [] [] u@(TUnknown _) = do u =?= REmpty
776832 return []
777− go [] [] (Skolem _) | lax = return []
833+ go [] [] (Skolem _ _) | lax = return []
778834 go [] ((p, _): _) _ | lax = return []
779835 | otherwise = throwError $ prettyPrintValue (ObjectLiteral ps) ++ " does not have property " ++ p
780836 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
801857-- |
802858-- Check the type of a function application, rethrowing errors to provide a better error message
803859--
804−checkFunctionApplication :: Value -> Type -> Value -> Type -> UnifyT Type Check Value
805−checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionApplication' fn fnTy arg ret
860+checkFunctionApplication :: Value -> Type -> Value -> UnifyT Type Check (Type, Value)
861+checkFunctionApplication fn fnTy arg = rethrow errorMessage $ checkFunctionApplication' fn fnTy arg
806862 where
807863 errorMessage msg = "Error applying function of type "
808864 ++ prettyPrintType fnTy
@@ -812,34 +868,33 @@ checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionA
812868-- |
813869-- Check the type of a function application
814870--
815−checkFunctionApplication' :: Value -> Type -> Value -> Type -> UnifyT Type Check Value
816−checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg ret = do
871+checkFunctionApplication' :: Value -> Type -> Value -> UnifyT Type Check (Type, Value)
872+checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg = do
817873 tyFunction' =?= tyFunction
818874 arg' <- check arg argTy
819− _ <- subsumes Nothing retTy ret
820− return $ App fn arg'
821−checkFunctionApplication' fn (ForAll ident ty) arg ret = do
875+ return (retTy, App fn arg')
876+checkFunctionApplication' fn (ForAll ident ty _) arg = do
822877 replaced <- replaceVarWithUnknown ident ty
823− checkFunctionApplication fn replaced arg ret
824−checkFunctionApplication' fn u@(TUnknown _) arg ret = do
878+ checkFunctionApplication fn replaced arg
879+checkFunctionApplication' fn u@(TUnknown _) arg = do
825880 arg' <- do
826881 TypedValue _ v t <- infer arg
827882 TypedValue True v <$> replaceAllVarsWithUnknowns t
828883 let ty = (\(TypedValue _ _ t) -> t) arg'
884+ ret <- fresh
829885 u =?= function ty ret
830− return $ App fn arg'
831−checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
832− ty <- expandTypeSynonym name tyArgs
833− checkFunctionApplication fn ty arg ret
834−checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
886+ return (ret, App fn arg')
887+checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg = do
888+ ty <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
889+ checkFunctionApplication fn ty arg
890+checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg = do
835891 env <- getEnv
836892 dicts <- getTypeClassDictionaries
837893 Just moduleName <- checkCurrentModule <$> get
838− checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) fnTy arg ret
839−checkFunctionApplication' _ fnTy arg ret = throwError $ "Applying a function of type "
894+ checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) (qualifyAllUnqualifiedNames moduleName env constraints))) fnTy arg
895+checkFunctionApplication' _ fnTy arg = throwError $ "Cannot apply a function of type "
840896 ++ prettyPrintType fnTy
841− ++ " to argument(s) " ++ prettyPrintValue arg
842− ++ " does not yield a value of type " ++ prettyPrintType ret ++ "."
897+ ++ " to argument " ++ prettyPrintValue arg
843898
844899-- |
845900-- 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
857912-- Check whether one type subsumes another
858913--
859914subsumes' :: 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
861916 replaced <- replaceVarWithUnknown ident ty1
862917 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"
863925subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
864926 subsumes Nothing arg2 arg1
865927 subsumes Nothing ret1 ret2
866928 return val
867929subsumes' val (SaturatedTypeSynonym name tyArgs) ty2 = do
868− ty1 <- expandTypeSynonym name tyArgs
930+ ty1 <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
869931 subsumes val ty1 ty2
870932subsumes' val ty1 (SaturatedTypeSynonym name tyArgs) = do
871− ty2 <- expandTypeSynonym name tyArgs
933+ ty2 <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
872934 subsumes val ty1 ty2
873935subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
874936 env <- getEnv
src/Language/PureScript/Types.hs+10−5
@@ -24,6 +24,11 @@ import Control.Monad.Unify
2424
2525import Language.PureScript.Names
2626
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+
2732-- |
2833-- The type of types
2934--
@@ -55,7 +60,7 @@ data Type
5560 -- |
5661 -- Forall quantifier
5762 --
58− | ForAll String Type
63+ | ForAll String Type (Maybe SkolemScope)
5964 -- |
6065 -- A type with a set of type class constraints
6166 --
@@ -63,7 +68,7 @@ data Type
6368 -- |
6469 -- A skolem constant
6570 --
66− | Skolem Int
71+ | Skolem Int SkolemScope
6772 -- |
6873 -- An empty row
6974 --
@@ -128,14 +133,14 @@ rowFromList ((name, t):ts, r) = RCons name t (rowFromList (ts, r))
128133-- Check whether a type is a monotype
129134--
130135isMonoType :: Type -> Bool
131−isMonoType (ForAll _ _) = False
136+isMonoType (ForAll _ _ _) = False
132137isMonoType ty = True
133138
134139-- |
135140-- Universally quantify a type
136141--
137142mkForAll :: [String] -> Type -> Type
138−mkForAll = flip . foldl . flip $ ForAll
143+mkForAll args ty = foldl (\t arg -> ForAll arg t Nothing) ty args
139144
140145-- |
141146-- The empty record type
@@ -151,5 +156,5 @@ replaceTypeVars name t = everywhereBut (mkQ False isShadowed) (mkT replaceTypeVa
151156 where
152157 replaceTypeVar (TypeVar v) | v == name = t
153158 replaceTypeVar other = other
154− isShadowed (ForAll v _) | v == name = True
159+ isShadowed (ForAll v _ _) | v == name = True
155160 isShadowed _ = False