@@ -1,6 +1,6 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Type.Environment
2module Type.Environment
4 , initialize
4 , initialize
5 , getType, freshDataScheme, ctorNames
5 , getType, freshDataScheme, ctorNames
6 , addValues
6 , addValues
@@ -24,18 +24,18 @@ type TypeDict = Map.Map String Type
24type VarDict = Map.Map String Variable
24type VarDict = Map.Map String Variable
27−data Environment = Environment
27+data Env = Env
28 { _constructor :: Map.Map String (IO (Int, [Variable], [Type], Type))
28 { _constructor :: Map.Map String (IO (Int, [Variable], [Type], Type))
29 , _types :: TypeDict
29 , _types :: TypeDict
30 , _value :: TypeDict
30 , _value :: TypeDict
34−initialize :: [Module.CanonicalUnion] -> IO Environment
34+initialize :: [Module.CanonicalUnion] -> IO Env
35initialize datatypes =
35initialize datatypes =
36 do types <- makeTypes datatypes
36 do types <- makeTypes datatypes
39 { _constructor = Map.empty
39 { _constructor = Map.empty
40 , _value = Map.empty
40 , _value = Map.empty
41 , _types = types
41 , _types = types
@@ -72,7 +72,7 @@ makeTypes datatypes =
74makeConstructors
74makeConstructors
75− :: Environment
75+ :: Env
76 -> [Module.CanonicalUnion]
76 -> [Module.CanonicalUnion]
77 -> Map.Map String (IO (Int, [Variable], [Type], Type))
77 -> Map.Map String (IO (Int, [Variable], [Type], Type))
78makeConstructors env datatypes =
78makeConstructors env datatypes =
@@ -100,7 +100,7 @@ makeConstructors env datatypes =
102ctorToType
102ctorToType
103− :: Environment
103+ :: Env
104 -> (V.Canonical, Module.UnionInfo V.Canonical)
104 -> (V.Canonical, Module.UnionInfo V.Canonical)
105 -> [(String, IO (Int, [Variable], [Type], Type))]
105 -> [(String, IO (Int, [Variable], [Type], Type))]
106ctorToType env (name, (tvars, ctors)) =
106ctorToType env (name, (tvars, ctors)) =
@@ -123,24 +123,24 @@ ctorToType env (name, (tvars, ctors)) =
123-- ACCESS TYPES
123-- ACCESS TYPES
126−get :: (Environment -> Map.Map String a) -> Environment -> String -> a
126+get :: (Env -> Map.Map String a) -> Env -> String -> a
127get subDict env key =
127get subDict env key =
128 Map.findWithDefault (error msg) key (subDict env)
128 Map.findWithDefault (error msg) key (subDict env)
130 msg = "Could not find type constructor `" ++ key ++ "` while checking types."
130 msg = "Could not find type constructor `" ++ key ++ "` while checking types."
133−getType :: Environment -> String -> Type
133+getType :: Env -> String -> Type
135 get _types
135 get _types
138−freshDataScheme :: Environment -> String -> IO (Int, [Variable], [Type], Type)
138+freshDataScheme :: Env -> String -> IO (Int, [Variable], [Type], Type)
139freshDataScheme =
139freshDataScheme =
140 get _constructor
140 get _constructor
143−ctorNames :: Environment -> [String]
143+ctorNames :: Env -> [String]
144ctorNames env =
144ctorNames env =
145 Map.keys (_constructor env)
145 Map.keys (_constructor env)
@@ -148,7 +148,7 @@ ctorNames env =
148-- UPDATE ENVIRONMENT
148-- UPDATE ENVIRONMENT
151−addValues :: Environment -> [(String, Variable)] -> Environment
151+addValues :: Env -> [(String, Variable)] -> Env
152addValues env newValues =
152addValues env newValues =
154 { _value =
154 { _value =
@@ -163,18 +163,18 @@ addValues env newValues =
163-- INSTANTIATE TYPES
163-- INSTANTIATE TYPES
166−instantiateType :: Environment -> T.Canonical -> VarDict -> IO ([Variable], Type)
166+instantiateType :: Env -> T.Canonical -> VarDict -> IO ([Variable], Type)
167instantiateType env sourceType dict =
167instantiateType env sourceType dict =
168 do (tipe, dict') <- State.runStateT (instantiator env sourceType) dict
168 do (tipe, dict') <- State.runStateT (instantiator env sourceType) dict
169 return (Map.elems dict', tipe)
169 return (Map.elems dict', tipe)
172−instantiator :: Environment -> T.Canonical -> State.StateT VarDict IO Type
172+instantiator :: Env -> T.Canonical -> State.StateT VarDict IO Type
173instantiator env sourceType =
173instantiator env sourceType =
174 instantiatorHelp env Set.empty sourceType
174 instantiatorHelp env Set.empty sourceType
177−instantiatorHelp :: Environment -> Set.Set String -> T.Canonical -> State.StateT VarDict IO Type
177+instantiatorHelp :: Env -> Set.Set String -> T.Canonical -> State.StateT VarDict IO Type
178instantiatorHelp env aliasVars sourceType =
178instantiatorHelp env aliasVars sourceType =