@@ -25,15 +25,26 @@ data Pool = Pool {
2525emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
2626
2727-- Keeps track of the environment, type variable pool, and a list of errors
28−type SolverState = (Map.Map String Variable, Pool, Int, [IO P.Doc])
29−
30−-- The mark must never be equal to noMark!
31−initialState = (Map.empty, emptyPool, noMark + 1, [])
32−
33−modifyEnv f = modify $ \(env, pool, mark, errors) -> (f env, pool, mark, errors)
34−modifyPool f = modify $ \(env, pool, mark, errors) -> (env, f pool, mark, errors)
28+data SolverState = SS {
29+ sEnv :: Map.Map String Variable,
30+ sSavedEnv :: Map.Map String Variable,
31+ sPool :: Pool,
32+ sMark :: Int,
33+ sErrors :: [IO P.Doc]
34+}
35+
36+initialState = SS {
37+ sEnv = Map.empty,
38+ sSavedEnv = Map.empty,
39+ sPool = emptyPool,
40+ sMark = noMark + 1, -- The mark must never be equal to noMark!
41+ sErrors = []
42+}
43+
44+modifyEnv f = modify $ \state -> state { sEnv = f (sEnv state) }
45+modifyPool f = modify $ \state -> state { sPool = f (sPool state) }
3546addError message t1 t2 =
36− modify $ \(env, pool, mark, errors) -> (env, pool, mark, err : errors)
47+ modify $ \state -> state { sErrors = err : sErrors state }
3748 where
3849 wordify = P.fsep . map P.text . words
3950 msg = wordify message
@@ -53,19 +64,21 @@ addError message t1 t2 =
5364switchToPool pool = modifyPool (\_ -> pool)
5465
5566getPool :: StateT SolverState IO Pool
56−getPool = do
57− (_, pool, _, _) <- get
58− return pool
67+getPool = sPool <$> get
5968
6069getEnv :: StateT SolverState IO (Map.Map String Variable)
61−getEnv = do
62− (env, _, _, _) <- get
63− return env
70+getEnv = sEnv <$> get
71+
72+saveLocalEnv :: StateT SolverState IO ()
73+saveLocalEnv = do
74+ env <- sEnv <$> get
75+ modify $ \state -> state { sSavedEnv = env }
6476
6577uniqueMark :: StateT SolverState IO Int
6678uniqueMark = do
67− (env, pool, mark, errs) <- get
68− put (env, pool, mark+1, errs)
79+ state <- get
80+ let mark = sMark state
81+ put $ state { sMark = mark + 1 }
6982 return mark
7083
7184nextRankPool :: StateT SolverState IO Pool