@@ -1,5 +1,25 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2−module Type.State where
2+module Type.State
4import qualified Control.Monad.State as State
24import qualified Control.Monad.State as State
5import qualified Data.Map as Map
25import qualified Data.Map as Map
@@ -13,33 +33,28 @@ import qualified Reporting.Region as R
13import Type.Type
33import Type.Type
17−-- Holds a bunch of variables
18−-- The rank of each variable is less than or equal to the pool's "maxRank"
19−-- The young pool exists to make it possible to identify these vars in constant time.
24− , inhabitants :: [Variable]
39+type Solver = State.StateT SolverState IO
31− { maxRank = outermostRank
42+run :: Solver () -> IO SolverState
44+ State.execStateT solver $
47+ , sSavedEnv = Map.empty
48+ , sPool = Pool outermostRank []
49+ , sMark = noMark + 1 -- The mark must never be equal to noMark!
36−type Env = Map.Map Text (A.Located Variable)
39−type Solver = State.StateT SolverState IO
55+-- SOLVER STATE
42−-- Keeps track of the environment, type variable pool, and a list of errors
43data SolverState =
58data SolverState =
45 { sEnv :: Env
60 { sEnv :: Env
@@ -50,17 +65,24 @@ data SolverState =
53−initialState :: SolverState
68+{-| A pool holds a bunch of variables
54−initialState =
69+The rank of each variable is less than or equal to the pool's "maxRank"
55− SS
70+The young pool exists to make it possible to identify these vars in constant time.
56− { sEnv = Map.empty
71+-}
57− , sSavedEnv = Map.empty
72+data Pool =
58− , sPool = emptyPool
73+ Pool
59− , sMark = noMark + 1 -- The mark must never be equal to noMark!
74+ { maxRank :: Int
60− , sError = []
75+ , inhabitants :: [Variable]
79+type Env = Map.Map Text (A.Located Variable)
64modifyEnv :: (Env -> Env) -> Solver ()
86modifyEnv :: (Env -> Env) -> Solver ()
65modifyEnv f =
87modifyEnv f =
66 State.modify $ \state -> state { sEnv = f (sEnv state) }
88 State.modify $ \state -> state { sEnv = f (sEnv state) }