Add the ExtraChecks module to do occurs check and check the type of main

This commit is contained in:
Evan Czaplicki 2013-08-19 16:54:46 -07:00
parent 8d09047b76
commit 4da7588d10
3 changed files with 22 additions and 3 deletions

View file

@ -68,6 +68,7 @@ Library
Type.Constrain.Literal,
Type.Constrain.Pattern,
Type.Environment,
Type.ExtraChecks,
Type.Fragment,
Type.Inference,
Type.PrettyPrint,
@ -136,6 +137,7 @@ Executable elm
Type.Constrain.Literal,
Type.Constrain.Pattern,
Type.Environment,
Type.ExtraChecks,
Type.Fragment,
Type.Inference,
Type.PrettyPrint,

View file

@ -0,0 +1,15 @@
-- This module contains checks to be run *after* type inference has
-- completed successfully. At that point we still need to do occurs
-- checks and ensure that `main` has an acceptable type.
module Type.ExtraChecks where
import qualified Data.Map as Map
import Type.State (Env)
mainCheck :: Env -> IO (Either String Env)
mainCheck env =
case Map.lookup "main" env of
Nothing -> return (Right env)
Just var -> return (Right env)
occursCheck = undefined

View file

@ -24,10 +24,12 @@ data Pool = Pool {
emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
type Env = Map.Map String Variable
-- Keeps track of the environment, type variable pool, and a list of errors
data SolverState = SS {
sEnv :: Map.Map String Variable,
sSavedEnv :: Map.Map String Variable,
sEnv :: Env,
sSavedEnv :: Env,
sPool :: Pool,
sMark :: Int,
sErrors :: [IO P.Doc]
@ -77,7 +79,7 @@ switchToPool pool = modifyPool (\_ -> pool)
getPool :: StateT SolverState IO Pool
getPool = sPool <$> get
getEnv :: StateT SolverState IO (Map.Map String Variable)
getEnv :: StateT SolverState IO Env
getEnv = sEnv <$> get
saveLocalEnv :: StateT SolverState IO ()