on master help sign in
Move type annotations out of Environment and into the Basics library
commitec8687610feb93466cbb03a64cb11d8077d33e16 authorEvan Czaplicki <info@elm-lang.org> dateFri 26 Jul 2013, 00:06 (13 years ago) parent4e1f79c
1 file changed+9−29
compiler/Type/Environment.hs+9−29
compiler/Type/Environment.hs+9−29
@@ -54,23 +54,13 @@ makeConstructors types = Map.fromList builtins
5454 where
5555 list t = (types ! "_List") <| t
5656 maybe t = (types ! "Maybe") <| t
57− bool = types ! "Bool"
58− int = types ! "Int"
59− float = types ! "Float"
60− order = types ! "Order"
61−
62− instance' :: IO Variable -> Int -> ([Type] -> ([Type], Type))
63− -> IO (Int, [Variable], [Type], Type)
64− instance' var numTVars tipe = do
65− vars <- forM [1..numTVars] $ \_ -> var
57+
58+ inst :: Int -> ([Type] -> ([Type], Type)) -> IO (Int, [Variable], [Type], Type)
59+ inst numTVars tipe = do
60+ vars <- forM [1..numTVars] $ \_ -> var Flexible
6661 let (args, result) = tipe (map VarN vars)
6762 return (length args, vars, args, result)
6863
69− inst = instance' (var Flexible)
70− nmbr = instance' (var (Is Number)) 1
71− cmpr = instance' (var (Is Comparable)) 1
72− apnd = instance' (var (Is Appendable)) 1
73−
7464 tupleCtor n =
7565 let name = "_Tuple" ++ show n
7666 in (name, inst n $ \vs -> (vs, foldl (<|) (types ! name) vs))
@@ -80,19 +70,6 @@ makeConstructors types = Map.fromList builtins
8070 , ("Just" , inst 1 $ \ [t] -> ([t], maybe t))
8171 , ("[]" , inst 1 $ \ [t] -> ([], list t))
8272 , ("::" , inst 1 $ \ [t] -> ([t, list t], list t))
83− , ("div" , inst 0 $ \ [] -> ([int, int], int))
84− , ("/" , inst 0 $ \ [] -> ([float, float], float))
85− , ("+" , nmbr $ \ [t] -> ([t, t], t))
86− , ("-" , nmbr $ \ [t] -> ([t, t], t))
87− , ("*" , nmbr $ \ [t] -> ([t, t], t))
88− , ("<" , cmpr $ \ [t] -> ([t, t], bool))
89− , (">" , cmpr $ \ [t] -> ([t, t], bool))
90− , ("<=" , cmpr $ \ [t] -> ([t, t], bool))
91− , (">=" , cmpr $ \ [t] -> ([t, t], bool))
92− , ("==" , cmpr $ \ [t] -> ([t, t], bool))
93− , ("/=" , cmpr $ \ [t] -> ([t, t], bool))
94− , ("compare", cmpr $ \ [t] -> ([t, t], order))
95− , ("otherwise", inst 0 $ \ [] -> ([], bool))
9673 ] ++ map tupleCtor [0..9]
9774
9875
@@ -121,7 +98,7 @@ instantiateTypeWithContext env sourceType dict =
12198 go :: Src.Type -> State.StateT (Map.Map String Variable) IO Type
12299 go sourceType =
123100 case sourceType of
124− Src.Lambda t1 t2 -> TermN <$> (Fun1 <$> go t1 <*> go t2)
101+ Src.Lambda t1 t2 -> (==>) <$> go t1 <*> go t2
125102
126103 Src.Var x -> do
127104 dict <- State.get
@@ -137,9 +114,12 @@ instantiateTypeWithContext env sourceType dict =
137114 | "appendable" `isPrefixOf` x = Is Appendable
138115 | otherwise = Flexible
139116
117+ Src.Data "String" [] ->
118+ return (get env types "_List" <| get env types "Char")
119+
140120 Src.Data name ts -> do
141121 ts' <- mapM go ts
142− return $ foldl (\tyFn ty -> TermN $ App1 tyFn ty) (get env types name) ts'
122+ return $ foldl (<|) (get env types name) ts'
143123
144124 Src.EmptyRecord -> return (TermN EmptyRecord1)
145125