@@ -9,8 +9,8 @@ import Type.PrettyPrint
9import Text.PrettyPrint as P
9import Text.PrettyPrint as P
10import System.IO.Unsafe
10import System.IO.Unsafe
11import Control.Applicative ((<$>),(<*>))
11import Control.Applicative ((<$>),(<*>))
12−import Control.Monad.State
12+import Control.Monad.State (StateT, get, put, execStateT, runStateT)
13−import Control.Monad.Error
13+import Control.Monad.Error (ErrorT, Error, liftIO)
14import Data.Traversable (traverse)
14import Data.Traversable (traverse)
15import AST.Annotation
15import AST.Annotation
16import qualified AST.PrettyPrint as PP
16import qualified AST.PrettyPrint as PP
@@ -65,6 +65,7 @@ data Scheme a b = Scheme {
65type TypeConstraint = Constraint Type Variable
65type TypeConstraint = Constraint Type Variable
66type TypeScheme = Scheme Type Variable
66type TypeScheme = Scheme Type Variable
68+monoscheme :: Map.Map String a -> Scheme a b
68monoscheme headers = Scheme [] [] (noneNoDocs CTrue) headers
69monoscheme headers = Scheme [] [] (noneNoDocs CTrue) headers
70infixl 8 /\
71infixl 8 /\
@@ -80,6 +81,7 @@ infixr 9 ==>
80(==>) :: Type -> Type -> Type
81(==>) :: Type -> Type -> Type
81a ==> b = termN (Fun1 a b)
82a ==> b = termN (Fun1 a b)
84+(<|) :: TermN a -> TermN a -> TermN a
83f <| a = termN (App1 f a)
85f <| a = termN (App1 f a)
85data Descriptor = Descriptor
87data Descriptor = Descriptor
@@ -92,10 +94,16 @@ data Descriptor = Descriptor
92 , alias :: Maybe Var.Canonical
94 , alias :: Maybe Var.Canonical
93 } deriving Show
95 } deriving Show
95noRank = -1
98noRank = -1
96−outermostRank = 0 :: Int
98noMark = 0
104noMark = 0
99initialMark = 1
107initialMark = 1
101data Flex = Rigid | Flexible | Constant | Is SuperType
109data Flex = Rigid | Flexible | Constant | Is SuperType
@@ -115,8 +123,8 @@ namedVar flex name = UF.fresh $ Descriptor
115 , alias = Nothing
123 , alias = Nothing
118−var :: Flex -> IO Variable
126+variable :: Flex -> IO Variable
119−var flex = UF.fresh $ Descriptor
127+variable flex = UF.fresh $ Descriptor
120 { structure = Nothing
128 { structure = Nothing
121 , rank = noRank
129 , rank = noRank
122 , flex = flex
130 , flex = flex
@@ -139,12 +147,12 @@ fl rqs constraint@(A ann _) =
140exists :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint
148exists :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint
141exists f = do
149exists f = do
142− v <- liftIO $ var Flexible
150+ v <- liftIO $ variable Flexible
143 ex [v] <$> f (varN v)
151 ex [v] <$> f (varN v)
145existsNumber :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint
153existsNumber :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint
146existsNumber f = do
154existsNumber f = do
147− v <- liftIO $ var (Is Number)
155+ v <- liftIO $ variable (Is Number)
148 ex [v] <$> f (varN v)
156 ex [v] <$> f (varN v)
@@ -278,7 +286,7 @@ addNames value = do
278 (rawVars, _, _, _) <- execStateT (crawl getNames value) ([], 0, 0, 0)
286 (rawVars, _, _, _) <- execStateT (crawl getNames value) ([], 0, 0, 0)
279 let vars = map head . List.group $ List.sort rawVars
287 let vars = map head . List.group $ List.sort rawVars
280 suffix s = map (++s) (map (:[]) ['a'..'z'])
288 suffix s = map (++s) (map (:[]) ['a'..'z'])
281− allVars = concatMap suffix $ ["","'","_"] ++ map show [0..]
289+ allVars = concatMap suffix $ ["","'","_"] ++ map show [ (0 :: Int) .. ]
282 okayVars = filter (`notElem` vars) allVars
290 okayVars = filter (`notElem` vars) allVars
283 runStateT (crawl rename value) (okayVars, 0, 0, 0)
291 runStateT (crawl rename value) (okayVars, 0, 0, 0)
284 return value
292 return value
@@ -366,21 +374,21 @@ instance Crawl Descriptor where
368toSrcType :: Variable -> IO T.CanonicalType
376toSrcType :: Variable -> IO T.CanonicalType
369−toSrcType variable =
377+toSrcType var =
370− do desc <- UF.descriptor =<< addNames variable
378+ do desc <- UF.descriptor =<< addNames var
371 srcType <- maybe (backupSrcType desc) termToSrcType (structure desc)
379 srcType <- maybe (backupSrcType desc) termToSrcType (structure desc)
372 return $ maybe srcType (\name -> T.Aliased name srcType) (alias desc)
380 return $ maybe srcType (\name -> T.Aliased name srcType) (alias desc)
374 backupSrcType desc =
382 backupSrcType desc =
375 case name desc of
383 case name desc of
376− Just var@(Var.Canonical _ x@(c:_))
384+ Just v@(Var.Canonical _ x@(c:_))
377 | Char.isLower c -> return (T.Var x)
385 | Char.isLower c -> return (T.Var x)
378− | otherwise -> return $ T.Type var
386+ | otherwise -> return $ T.Type v
380 _ -> error $ concat
388 _ -> error $ concat
381 [ "Problem converting the following type "
389 [ "Problem converting the following type "
382 , "from a type-checker type to a source-syntax type:"
390 , "from a type-checker type to a source-syntax type:"
383− , P.render (pretty Never variable) ]
391+ , P.render (pretty Never var) ]
385 termToSrcType term =
393 termToSrcType term =
386 case term of
394 case term of
@@ -410,10 +418,10 @@ toSrcType variable =
410data AppStructure = List Variable | Tuple [Variable] | Other
418data AppStructure = List Variable | Tuple [Variable] | Other
412collectApps :: Variable -> IO AppStructure
420collectApps :: Variable -> IO AppStructure
413−collectApps variable = go [] variable
421+collectApps var = go [] var
415− go vars variable = do
423+ go vars var = do
416− desc <- UF.descriptor variable
424+ desc <- UF.descriptor var
417 case (structure desc, vars) of
425 case (structure desc, vars) of
418 (Nothing, [v]) -> case name desc of
426 (Nothing, [v]) -> case name desc of
419 Just n | Var.isList n -> return (List v)
427 Just n | Var.isList n -> return (List v)