@@ -12,7 +12,7 @@ import qualified SourceSyntax.Type as Src
12import Type.Type
12import Type.Type
14data Environment = Environment {
14data Environment = Environment {
15− constructor :: Map.Map String (IO (Int, [Variable], Type)),
15+ constructor :: Map.Map String (IO (Int, [Variable], [Type], Type)),
16 types :: Map.Map String Type,
16 types :: Map.Map String Type,
17 value :: Map.Map String Type
17 value :: Map.Map String Type
@@ -48,26 +48,27 @@ makeTypes datatypes =
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))
52makeConstructors types = Map.fromList builtins
52makeConstructors types = Map.fromList builtins
54 list t = (types ! "_List") <| t
54 list t = (types ! "_List") <| t
55 maybe t = (types ! "Maybe") <| t
55 maybe t = (types ! "Maybe") <| t
57− inst :: Int -> Int -> ([Type] -> Type) -> IO (Int, [Variable], Type)
57+ inst :: Int -> Int -> ([Type] -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
58 inst kind numTVars tipe = do
58 inst kind numTVars tipe = do
59 vars <- forM [1..numTVars] $ \_ -> flexibleVar
59 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)
62 tupleCtor n =
63 tupleCtor n =
63 let name = "_Tuple" ++ show n
64 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))
66− builtins :: [ (String, IO (Int, [Variable], Type)) ]
67+ builtins :: [ (String, IO (Int, [Variable], [Type], Type)) ]
67− builtins = [ ("Nothing", inst 0 1 $ \ [t] -> maybe t)
68+ builtins = [ ("Nothing", inst 0 1 $ \ [t] -> ([], maybe t))
68− , ("Just" , inst 1 1 $ \ [t] -> t ==> maybe t)
69+ , ("Just" , inst 1 1 $ \ [t] -> ([t], maybe t))
69− , ("[]" , inst 0 1 $ \ [t] -> list t)
70+ , ("[]" , inst 0 1 $ \ [t] -> ([], list t))
70− , ("::" , inst 2 1 $ \ [t] -> t ==> list t ==> list t)
71+ , ("::" , inst 2 1 $ \ [t] -> ([t, list t], list t))
71 ] ++ map tupleCtor [0..9]
72 ] ++ map tupleCtor [0..9]
@@ -77,7 +78,7 @@ get env subDict key = Map.findWithDefault err key (subDict env)
77 err = error $ "Could not find '" ++ key ++ "' in the type environment."
78 err = error $ "Could not find '" ++ key ++ "' in the type environment."
80−freshDataScheme :: Environment -> String -> IO (Int, [Variable], Type)
81+freshDataScheme :: Environment -> String -> IO (Int, [Variable], [Type], Type)
81freshDataScheme env name = get env constructor name
82freshDataScheme env name = get env constructor name