on master help sign in
Add the ExtraChecks module to do occurs check and check the type of main
4da7588Evan Czaplicki
Elm.cabal+2
@@ -68,6 +68,7 @@ Library
68 Type.Constrain.Literal,
68 Type.Constrain.Literal,
69 Type.Constrain.Pattern,
69 Type.Constrain.Pattern,
70 Type.Environment,
70 Type.Environment,
71+ Type.ExtraChecks,
71 Type.Fragment,
72 Type.Fragment,
72 Type.Inference,
73 Type.Inference,
73 Type.PrettyPrint,
74 Type.PrettyPrint,
@@ -136,6 +137,7 @@ Executable elm
136 Type.Constrain.Literal,
137 Type.Constrain.Literal,
137 Type.Constrain.Pattern,
138 Type.Constrain.Pattern,
138 Type.Environment,
139 Type.Environment,
140+ Type.ExtraChecks,
139 Type.Fragment,
141 Type.Fragment,
140 Type.Inference,
142 Type.Inference,
141 Type.PrettyPrint,
143 Type.PrettyPrint,
compiler/Type/ExtraChecks.hsnew file+15
@@ -0,0 +1,15 @@
1+-- This module contains checks to be run *after* type inference has
2+-- completed successfully. At that point we still need to do occurs
3+-- checks and ensure that `main` has an acceptable type.
4+module Type.ExtraChecks where
5+
6+import qualified Data.Map as Map
7+import Type.State (Env)
8+
9+mainCheck :: Env -> IO (Either String Env)
10+mainCheck env =
11+ case Map.lookup "main" env of
12+ Nothing -> return (Right env)
13+ Just var -> return (Right env)
14+
15+occursCheck = undefined
compiler/Type/State.hs+5−3
@@ -24,10 +24,12 @@ data Pool = Pool {
24
24
25emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
25emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
26
26
27+type Env = Map.Map String Variable
28+
27-- Keeps track of the environment, type variable pool, and a list of errors
29-- Keeps track of the environment, type variable pool, and a list of errors
28data SolverState = SS {
30data SolverState = SS {
29− sEnv :: Map.Map String Variable,
31+ sEnv :: Env,
30− sSavedEnv :: Map.Map String Variable,
32+ sSavedEnv :: Env,
31 sPool :: Pool,
33 sPool :: Pool,
32 sMark :: Int,
34 sMark :: Int,
33 sErrors :: [IO P.Doc]
35 sErrors :: [IO P.Doc]
@@ -77,7 +79,7 @@ switchToPool pool = modifyPool (\_ -> pool)
77getPool :: StateT SolverState IO Pool
79getPool :: StateT SolverState IO Pool
78getPool = sPool <$> get
80getPool = sPool <$> get
79
81
80−getEnv :: StateT SolverState IO (Map.Map String Variable)
82+getEnv :: StateT SolverState IO Env
81getEnv = sEnv <$> get
83getEnv = sEnv <$> get
82
84
83saveLocalEnv :: StateT SolverState IO ()
85saveLocalEnv :: StateT SolverState IO ()