@@ -9,8 +9,8 @@ import Type.PrettyPrint
99import Text.PrettyPrint as P
1010import System.IO.Unsafe
1111import Control.Applicative ((<$>),(<*>))
12−import Control.Monad.State
13−import Control.Monad.Error
12+import Control.Monad.State (StateT, get, put, execStateT, runStateT)
13+import Control.Monad.Error (ErrorT, Error, liftIO)
1414import Data.Traversable (traverse)
1515import AST.Annotation
1616import qualified AST.PrettyPrint as PP
@@ -65,6 +65,7 @@ data Scheme a b = Scheme {
6565type TypeConstraint = Constraint Type Variable
6666type TypeScheme = Scheme Type Variable
6767
68+monoscheme :: Map.Map String a -> Scheme a b
6869monoscheme headers = Scheme [] [] (noneNoDocs CTrue) headers
6970
7071infixl 8 /\
@@ -80,6 +81,7 @@ infixr 9 ==>
8081(==>) :: Type -> Type -> Type
8182a ==> b = termN (Fun1 a b)
8283
84+(<|) :: TermN a -> TermN a -> TermN a
8385f <| a = termN (App1 f a)
8486
8587data Descriptor = Descriptor
@@ -92,10 +94,16 @@ data Descriptor = Descriptor
9294 , alias :: Maybe Var.Canonical
9395 } deriving Show
9496
97+noRank :: Int
9598noRank = -1
96−outermostRank = 0 :: Int
9799
100+outermostRank :: Int
101+outermostRank = 0
102+
103+noMark :: Int
98104noMark = 0
105+
106+initialMark :: Int
99107initialMark = 1
100108
101109data Flex = Rigid | Flexible | Constant | Is SuperType
@@ -115,8 +123,8 @@ namedVar flex name = UF.fresh $ Descriptor
115123 , alias = Nothing
116124 }
117125
118−var :: Flex -> IO Variable
119−var flex = UF.fresh $ Descriptor
126+variable :: Flex -> IO Variable
127+variable flex = UF.fresh $ Descriptor
120128 { structure = Nothing
121129 , rank = noRank
122130 , flex = flex
@@ -139,12 +147,12 @@ fl rqs constraint@(A ann _) =
139147
140148exists :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint
141149exists f = do
142− v <- liftIO $ var Flexible
150+ v <- liftIO $ variable Flexible
143151 ex [v] <$> f (varN v)
144152
145153existsNumber :: Error e => (Type -> ErrorT e IO TypeConstraint) -> ErrorT e IO TypeConstraint
146154existsNumber f = do
147− v <- liftIO $ var (Is Number)
155+ v <- liftIO $ variable (Is Number)
148156 ex [v] <$> f (varN v)
149157
150158
@@ -278,7 +286,7 @@ addNames value = do
278286 (rawVars, _, _, _) <- execStateT (crawl getNames value) ([], 0, 0, 0)
279287 let vars = map head . List.group $ List.sort rawVars
280288 suffix s = map (++s) (map (:[]) ['a'..'z'])
281− allVars = concatMap suffix $ ["","'","_"] ++ map show [0..]
289+ allVars = concatMap suffix $ ["","'","_"] ++ map show [ (0 :: Int) .. ]
282290 okayVars = filter (`notElem` vars) allVars
283291 runStateT (crawl rename value) (okayVars, 0, 0, 0)
284292 return value
@@ -366,21 +374,21 @@ instance Crawl Descriptor where
366374
367375
368376toSrcType :: Variable -> IO T.CanonicalType
369−toSrcType variable =
370− do desc <- UF.descriptor =<< addNames variable
377+toSrcType var =
378+ do desc <- UF.descriptor =<< addNames var
371379 srcType <- maybe (backupSrcType desc) termToSrcType (structure desc)
372380 return $ maybe srcType (\name -> T.Aliased name srcType) (alias desc)
373381 where
374382 backupSrcType desc =
375383 case name desc of
376− Just var@(Var.Canonical _ x@(c:_))
384+ Just v@(Var.Canonical _ x@(c:_))
377385 | Char.isLower c -> return (T.Var x)
378− | otherwise -> return $ T.Type var
386+ | otherwise -> return $ T.Type v
379387
380388 _ -> error $ concat
381389 [ "Problem converting the following type "
382390 , "from a type-checker type to a source-syntax type:"
383− , P.render (pretty Never variable) ]
391+ , P.render (pretty Never var) ]
384392
385393 termToSrcType term =
386394 case term of
@@ -410,10 +418,10 @@ toSrcType variable =
410418data AppStructure = List Variable | Tuple [Variable] | Other
411419
412420collectApps :: Variable -> IO AppStructure
413−collectApps variable = go [] variable
421+collectApps var = go [] var
414422 where
415− go vars variable = do
416− desc <- UF.descriptor variable
423+ go vars var = do
424+ desc <- UF.descriptor var
417425 case (structure desc, vars) of
418426 (Nothing, [v]) -> case name desc of
419427 Just n | Var.isList n -> return (List v)