on master help sign in
Rename Environment to Env in type inferencer
commit3b23d862387723998dd4351b44894e59654876c1 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 19 Sep 2016, 11:16 (10 years ago) parentafb08b8
6 files changed+30−52
src/Type/Constrain/Effects.hs+3−11 src/Type/Constrain/Expression.hs+10−19 src/Type/Constrain/Literal.hs+1−6 src/Type/Constrain/Pattern.hs+1−1 src/Type/Environment.hs+14−14 src/Type/Inference.hs+1−1
src/Type/Constrain/Effects.hs+3−11
@@ -14,11 +14,7 @@ import Type.Type
1414 )
1515
1616
17−constrain
18− :: Env.Environment
19− -> ModuleName.Canonical
20− -> Effects.Canonical
21− -> IO TypeConstraint
17+constrain :: Env.Env -> ModuleName.Canonical -> Effects.Canonical -> IO TypeConstraint
2218constrain env moduleName effects =
2319 case effects of
2420 Effects.None ->
@@ -31,11 +27,7 @@ constrain env moduleName effects =
3127 constrainHelp env moduleName info
3228
3329
34−constrainHelp
35− :: Env.Environment
36− -> ModuleName.Canonical
37− -> Effects.Info
38− -> IO TypeConstraint
30+constrainHelp :: Env.Env -> ModuleName.Canonical -> Effects.Info -> IO TypeConstraint
3931constrainHelp env moduleName (Effects.Info tagRegion r0 r1 r2 managerType) =
4032 let
4133 task t =
@@ -87,7 +79,7 @@ constrainHelp env moduleName (Effects.Info tagRegion r0 r1 r2 managerType) =
8779
8880
8981addEffectArgs
90− :: Env.Environment
82+ :: Env.Env
9183 -> ModuleName.Canonical
9284 -> Effects.ManagerType
9385 -> Variable
src/Type/Constrain/Expression.hs+10−19
@@ -22,11 +22,7 @@ import Type.Type hiding (Descriptor(..))
2222
2323
2424
25−constrain
26− :: Env.Environment
27− -> Canonical.Expr
28− -> Type
29− -> IO TypeConstraint
25+constrain :: Env.Env -> Canonical.Expr -> Type -> IO TypeConstraint
3026constrain env annotatedExpr@(A.A region expression) tipe =
3127 case expression of
3228 E.Literal lit ->
@@ -163,7 +159,7 @@ constrain env annotatedExpr@(A.A region expression) tipe =
163159
164160
165161constrainApp
166− :: Env.Environment
162+ :: Env.Env
167163 -> R.Region
168164 -> Canonical.Expr
169165 -> [Canonical.Expr]
@@ -192,7 +188,7 @@ constrainApp env region f args tipe =
192188
193189
194190argConstraints
195− :: Env.Environment
191+ :: Env.Env
196192 -> Maybe V.Canonical
197193 -> R.Region
198194 -> Int
@@ -246,7 +242,7 @@ argConstraints env name region totalArgs overallVar index args =
246242
247243
248244constrainBinop
249− :: Env.Environment
245+ :: Env.Env
250246 -> R.Region
251247 -> V.Canonical
252248 -> Canonical.Expr
@@ -281,12 +277,7 @@ constrainBinop env region op leftExpr@(A.A leftRegion _) rightExpr@(A.A rightReg
281277-- CONSTRAIN LISTS
282278
283279
284−constrainList
285− :: Env.Environment
286− -> R.Region
287− -> [Canonical.Expr]
288− -> Type
289− -> IO TypeConstraint
280+constrainList :: Env.Env -> R.Region -> [Canonical.Expr] -> Type -> IO TypeConstraint
290281constrainList env region exprs tipe =
291282 do (exprInfo, exprCons) <-
292283 unzip <$> mapM elementConstraint exprs
@@ -309,7 +300,7 @@ constrainList env region exprs tipe =
309300
310301
311302constrainIf
312− :: Env.Environment
303+ :: Env.Env
313304 -> R.Region
314305 -> [(Canonical.Expr, Canonical.Expr)]
315306 -> Canonical.Expr
@@ -368,7 +359,7 @@ constrainIf env region branches finally tipe =
368359
369360
370361constrainCase
371− :: Env.Environment
362+ :: Env.Env
372363 -> R.Region
373364 -> Canonical.Expr
374365 -> [(P.Canonical, Canonical.Expr)]
@@ -498,7 +489,7 @@ data Info = Info
498489 }
499490
500491
501−constrainDef :: Env.Environment -> Info -> Canonical.Def -> IO Info
492+constrainDef :: Env.Env -> Info -> Canonical.Def -> IO Info
502493constrainDef env info (Canonical.Def _ (A.A patternRegion pattern) expr maybeTipe) =
503494 let qs = [] -- should come from the def, but I'm not sure what would live there...
504495 in
@@ -514,7 +505,7 @@ constrainDef env info (Canonical.Def _ (A.A patternRegion pattern) expr maybeTip
514505
515506
516507constrainUnannotatedDef
517− :: Env.Environment
508+ :: Env.Env
518509 -> Info
519510 -> [String]
520511 -> R.Region
@@ -542,7 +533,7 @@ constrainUnannotatedDef env info qs patternRegion name expr =
542533
543534
544535constrainAnnotatedDef
545− :: Env.Environment
536+ :: Env.Env
546537 -> Info
547538 -> [String]
548539 -> R.Region
src/Type/Constrain/Literal.hs+1−6
@@ -7,12 +7,7 @@ import qualified Type.Type as T
77import qualified Type.Environment as Env
88
99
10−constrain
11− :: Env.Environment
12− -> R.Region
13− -> L.Literal
14− -> T.Type
15− -> IO T.TypeConstraint
10+constrain :: Env.Env -> R.Region -> L.Literal -> T.Type -> IO T.TypeConstraint
1611constrain env region literal tipe =
1712 do definiteType <- litType
1813 return (T.CEqual (Error.Literal name) region definiteType tipe)
src/Type/Constrain/Pattern.hs+1−1
@@ -55,7 +55,7 @@ infoToScheme (Info headers vars cons) =
5555-- CONSTRAIN PATTERN
5656
5757
58−constrain :: Env.Environment -> P.Canonical -> Type -> IO Info
58+constrain :: Env.Env -> P.Canonical -> Type -> IO Info
5959constrain env (A.A region pattern) tipe =
6060 let
6161 equal patternError leftType rightType =
src/Type/Environment.hs+14−14
@@ -1,6 +1,6 @@
11{-# OPTIONS_GHC -Wall #-}
22module Type.Environment
3− ( Environment
3+ ( Env
44 , initialize
55 , getType, freshDataScheme, ctorNames
66 , addValues
@@ -24,18 +24,18 @@ type TypeDict = Map.Map String Type
2424type VarDict = Map.Map String Variable
2525
2626
27−data Environment = Environment
27+data Env = Env
2828 { _constructor :: Map.Map String (IO (Int, [Variable], [Type], Type))
2929 , _types :: TypeDict
3030 , _value :: TypeDict
3131 }
3232
3333
34−initialize :: [Module.CanonicalUnion] -> IO Environment
34+initialize :: [Module.CanonicalUnion] -> IO Env
3535initialize datatypes =
3636 do types <- makeTypes datatypes
3737 let env =
38− Environment
38+ Env
3939 { _constructor = Map.empty
4040 , _value = Map.empty
4141 , _types = types
@@ -72,7 +72,7 @@ makeTypes datatypes =
7272
7373
7474makeConstructors
75− :: Environment
75+ :: Env
7676 -> [Module.CanonicalUnion]
7777 -> Map.Map String (IO (Int, [Variable], [Type], Type))
7878makeConstructors env datatypes =
@@ -100,7 +100,7 @@ makeConstructors env datatypes =
100100
101101
102102ctorToType
103− :: Environment
103+ :: Env
104104 -> (V.Canonical, Module.UnionInfo V.Canonical)
105105 -> [(String, IO (Int, [Variable], [Type], Type))]
106106ctorToType env (name, (tvars, ctors)) =
@@ -123,24 +123,24 @@ ctorToType env (name, (tvars, ctors)) =
123123-- ACCESS TYPES
124124
125125
126−get :: (Environment -> Map.Map String a) -> Environment -> String -> a
126+get :: (Env -> Map.Map String a) -> Env -> String -> a
127127get subDict env key =
128128 Map.findWithDefault (error msg) key (subDict env)
129129 where
130130 msg = "Could not find type constructor `" ++ key ++ "` while checking types."
131131
132132
133−getType :: Environment -> String -> Type
133+getType :: Env -> String -> Type
134134getType =
135135 get _types
136136
137137
138−freshDataScheme :: Environment -> String -> IO (Int, [Variable], [Type], Type)
138+freshDataScheme :: Env -> String -> IO (Int, [Variable], [Type], Type)
139139freshDataScheme =
140140 get _constructor
141141
142142
143−ctorNames :: Environment -> [String]
143+ctorNames :: Env -> [String]
144144ctorNames env =
145145 Map.keys (_constructor env)
146146
@@ -148,7 +148,7 @@ ctorNames env =
148148-- UPDATE ENVIRONMENT
149149
150150
151−addValues :: Environment -> [(String, Variable)] -> Environment
151+addValues :: Env -> [(String, Variable)] -> Env
152152addValues env newValues =
153153 env
154154 { _value =
@@ -163,18 +163,18 @@ addValues env newValues =
163163-- INSTANTIATE TYPES
164164
165165
166−instantiateType :: Environment -> T.Canonical -> VarDict -> IO ([Variable], Type)
166+instantiateType :: Env -> T.Canonical -> VarDict -> IO ([Variable], Type)
167167instantiateType env sourceType dict =
168168 do (tipe, dict') <- State.runStateT (instantiator env sourceType) dict
169169 return (Map.elems dict', tipe)
170170
171171
172−instantiator :: Environment -> T.Canonical -> State.StateT VarDict IO Type
172+instantiator :: Env -> T.Canonical -> State.StateT VarDict IO Type
173173instantiator env sourceType =
174174 instantiatorHelp env Set.empty sourceType
175175
176176
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
178178instantiatorHelp env aliasVars sourceType =
179179 let
180180 go =
src/Type/Inference.hs+1−1
@@ -68,7 +68,7 @@ genConstraints interfaces modul =
6868
6969
7070canonicalizeValues
71− :: Env.Environment
71+ :: Env.Env
7272 -> (ModuleName.Canonical, Module.Interface)
7373 -> IO [(String, ([T.Variable], T.Type))]
7474canonicalizeValues env (moduleName, iface) =