on master help sign in
Stop creating types for ADT's, use Constant and Flexible in the right place
commit4dc68acd60484caec350905206f8c666462a8df3 authorEvan Czaplicki <info@elm-lang.org> dateFri 19 Jul 2013, 18:01 (13 years ago) parent4c0f716
1 file changed+3−19
compiler/Type/Environment.hs+3−19
compiler/Type/Environment.hs+3−19
@@ -33,7 +33,7 @@ makeTypes datatypes =
3333 nameAndKind (name, tvars, _) = (name, length tvars)
3434
3535 makeCtor (name, kind) = do
36− ctor <- VarN <$> namedVar name
36+ ctor <- VarN <$> namedVar Constant name
3737 return (name, ctor)
3838
3939 tuple n = ("_Tuple" ++ show n, n)
@@ -46,11 +46,8 @@ makeTypes datatypes =
4646 , kind 0 ["Int","Float","Char","Bool","Element"]
4747 ]
4848
49−makeConstructors types datatypes =
50− Map.union (Map.fromList builtins) (Map.unions $ map (instances dummyEnv) datatypes)
49+makeConstructors types datatypes = Map.fromList builtins
5150 where
52− dummyEnv = Environment { constructor=Map.empty, types=types, value=Map.empty }
53−
5451 list t = (types ! "_List") <| t
5552 maybe t = (types ! "Maybe") <| t
5653
@@ -70,7 +67,6 @@ makeConstructors types datatypes =
7067 , ("::" , inst 2 1 $ \ [t] -> t ==> list t ==> list t)
7168 ] ++ map tupleCtor [0..9]
7269
73−
7470
7571get :: Environment -> (Environment -> Map.Map String a) -> String -> a
7672get env subDict key = Map.findWithDefault err key (subDict env)
@@ -82,18 +78,6 @@ freshDataScheme :: Environment -> String -> IO (Int, [Variable], Type)
8278freshDataScheme env name = get env constructor name
8379
8480
85−instances :: Environment
86− -> (String, [String], [(String, [Src.Type])])
87− -> Map.Map String (IO (Int, [Variable], Type))
88−instances env (name, tvars, ctors) = Map.fromList $ map go ctors
89− where
90− tipe = Src.Data name (map Src.Var tvars)
91−
92− go (ctor, tipes) = (,) ctor $ do
93− let funcType = foldr Src.Lambda tipe tipes
94− (vars, ttype) <- instantiateTypeWithContext env funcType Map.empty
95− return (length tipes, vars, ttype)
96−
9781instantiateType :: Environment -> Src.Type -> IO Type
9882instantiateType env sourceType =
9983 snd <$> instantiateTypeWithContext env sourceType Map.empty
@@ -116,7 +100,7 @@ instantiateTypeWithContext env sourceType dict =
116100 case Map.lookup x dict of
117101 Just var -> return (VarN var)
118102 Nothing -> do
119− var <- State.liftIO $ namedVar x -- should this be Constant or Flexible?
103+ var <- State.liftIO $ namedVar Flexible x -- should this be Constant or Flexible?
120104 State.put (Map.insert x var dict)
121105 return (VarN var)
122106