@@ -12,7 +12,7 @@ import qualified SourceSyntax.Type as Src
1212import Type.Type
1313
1414data Environment = Environment {
15− constructor :: Map.Map String (IO (Int, [Variable], Type)),
15+ constructor :: Map.Map String (IO (Int, [Variable], [Type], Type)),
1616 types :: Map.Map String Type,
1717 value :: Map.Map String Type
1818}
@@ -48,26 +48,27 @@ makeTypes datatypes =
4848 ]
4949
5050
51−makeConstructors :: Map.Map String Type -> Map.Map String (IO (Int, [Variable], Type))
51+makeConstructors :: Map.Map String Type -> Map.Map String (IO (Int, [Variable], [Type], Type))
5252makeConstructors types = Map.fromList builtins
5353 where
5454 list t = (types ! "_List") <| t
5555 maybe t = (types ! "Maybe") <| t
5656
57− inst :: Int -> Int -> ([Type] -> Type) -> IO (Int, [Variable], Type)
57+ inst :: Int -> Int -> ([Type] -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
5858 inst kind numTVars tipe = do
5959 vars <- forM [1..numTVars] $ \_ -> flexibleVar
60− return (kind, vars, tipe $ map VarN vars)
60+ let (args, result) = tipe (map VarN vars)
61+ return (kind, vars, args, result)
6162
6263 tupleCtor n =
6364 let name = "_Tuple" ++ show n
64− in (name, inst n n $ \vs -> foldr (==>) (foldl (<|) (types ! name) vs) vs)
65+ in (name, inst n n $ \vs -> (vs, foldl (<|) (types ! name) vs))
6566
66− builtins :: [ (String, IO (Int, [Variable], Type)) ]
67− builtins = [ ("Nothing", inst 0 1 $ \ [t] -> maybe t)
68− , ("Just" , inst 1 1 $ \ [t] -> t ==> maybe t)
69− , ("[]" , inst 0 1 $ \ [t] -> list t)
70− , ("::" , inst 2 1 $ \ [t] -> t ==> list t ==> list t)
67+ builtins :: [ (String, IO (Int, [Variable], [Type], Type)) ]
68+ builtins = [ ("Nothing", inst 0 1 $ \ [t] -> ([], maybe t))
69+ , ("Just" , inst 1 1 $ \ [t] -> ([t], maybe t))
70+ , ("[]" , inst 0 1 $ \ [t] -> ([], list t))
71+ , ("::" , inst 2 1 $ \ [t] -> ([t, list t], list t))
7172 ] ++ map tupleCtor [0..9]
7273
7374
@@ -77,7 +78,7 @@ get env subDict key = Map.findWithDefault err key (subDict env)
7778 err = error $ "Could not find '" ++ key ++ "' in the type environment."
7879
7980
80−freshDataScheme :: Environment -> String -> IO (Int, [Variable], Type)
81+freshDataScheme :: Environment -> String -> IO (Int, [Variable], [Type], Type)
8182freshDataScheme env name = get env constructor name
8283
8384