on master help sign in
Switch from [Def t v] to (LExpr t v) for program representation
b0f96a2Evan Czaplicki
compiler/SourceSyntax/Module.hs+1−1
@@ -26,7 +26,7 @@ data MetadataModule t v = MetadataModule {
26 path :: FilePath,
26 path :: FilePath,
27 exports :: [String],
27 exports :: [String],
28 imports :: [(String, ImportMethod)],
28 imports :: [(String, ImportMethod)],
29− defs :: [Def t v],
29+ program :: LExpr t v,
30 types :: Map.Map String T.Variable,
30 types :: Map.Map String T.Variable,
31 fixities :: [(Assoc, Int, String)],
31 fixities :: [(Assoc, Int, String)],
32 aliases :: [(String, [String], Type)],
32 aliases :: [(String, [String], Type)],
compiler/Type/Inference.hs+6−6
@@ -10,6 +10,7 @@ import qualified Type.Solve as Solve
10
10
11import SourceSyntax.Module
11import SourceSyntax.Module
12import qualified SourceSyntax.Expression as Expr
12import qualified SourceSyntax.Expression as Expr
13+import SourceSyntax.PrettyPrint
13import Text.PrettyPrint
14import Text.PrettyPrint
14import qualified Type.State as TS
15import qualified Type.State as TS
15import Control.Monad.State
16import Control.Monad.State
@@ -28,14 +29,13 @@ infer modul = unsafePerformIO $ do
28 do (_, vars, tipe) <- Env.freshDataScheme env name
29 do (_, vars, tipe) <- Env.freshDataScheme env name
29 return (name, (vars, tipe))
30 return (name, (vars, tipe))
30
31
31− let expr = Expr.dummyLet $ defs modul
32− vars = concatMap (fst . snd) ctors
32+ let vars = concatMap (fst . snd) ctors
33 header = Map.map snd (Map.fromList ctors)
33 header = Map.map snd (Map.fromList ctors)
34 environ = T.CLet [ T.Scheme vars [] T.CTrue header ]
34 environ = T.CLet [ T.Scheme vars [] T.CTrue header ]
35− constraint <- environ `fmap` TcExpr.constrain env expr (T.VarN var)
35+ constraint <- environ `fmap` TcExpr.constrain env (program modul) (T.VarN var)
36− print =<< T.extraPretty constraint
37− (env,_,_,errors) <- execStateT (Solve.solve constraint) TS.initialState
36+ state <- execStateT (Solve.solve constraint) TS.initialState
37+ let errors = TS.sErrors state
38 if null errors
38 if null errors
39− then return $ Right env
39+ then return $ Right (Map.difference (TS.sSavedEnv state) header)
40 else Left `fmap` sequence errors
40 else Left `fmap` sequence errors
41
41