on master help sign in
Add the ExtraChecks module to do occurs check and check the type of main
commit4da7588d10589a6c3e93b8135c18afa49eea8da1 authorEvan Czaplicki <info@elm-lang.org> dateMon 19 Aug 2013, 16:54 (13 years ago) parent8d09047
3 files changed+22−3
Elm.cabal+2 compiler/Type/ExtraChecks.hs+15 compiler/Type/State.hs+5−3
Elm.cabal+2
@@ -68,6 +68,7 @@ Library
6868 Type.Constrain.Literal,
6969 Type.Constrain.Pattern,
7070 Type.Environment,
71+ Type.ExtraChecks,
7172 Type.Fragment,
7273 Type.Inference,
7374 Type.PrettyPrint,
@@ -136,6 +137,7 @@ Executable elm
136137 Type.Constrain.Literal,
137138 Type.Constrain.Pattern,
138139 Type.Environment,
140+ Type.ExtraChecks,
139141 Type.Fragment,
140142 Type.Inference,
141143 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 {
2424
2525emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
2626
27+type Env = Map.Map String Variable
28+
2729-- Keeps track of the environment, type variable pool, and a list of errors
2830data SolverState = SS {
29− sEnv :: Map.Map String Variable,
30− sSavedEnv :: Map.Map String Variable,
31+ sEnv :: Env,
32+ sSavedEnv :: Env,
3133 sPool :: Pool,
3234 sMark :: Int,
3335 sErrors :: [IO P.Doc]
@@ -77,7 +79,7 @@ switchToPool pool = modifyPool (\_ -> pool)
7779getPool :: StateT SolverState IO Pool
7880getPool = sPool <$> get
7981
80−getEnv :: StateT SolverState IO (Map.Map String Variable)
82+getEnv :: StateT SolverState IO Env
8183getEnv = sEnv <$> get
8284
8385saveLocalEnv :: StateT SolverState IO ()