@@ -25,15 +25,26 @@ data Pool = Pool {
25emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
25emptyPool = Pool { maxRank = outermostRank, inhabitants = [] }
27-- Keeps track of the environment, type variable pool, and a list of errors
27-- Keeps track of the environment, type variable pool, and a list of errors
28+data SolverState = SS {
28−type SolverState = (Map.Map String Variable, Pool, Int, [IO P.Doc])
29+ sEnv :: Map.Map String Variable,
29−
30+ sSavedEnv :: Map.Map String Variable,
33+ sErrors :: [IO P.Doc]
38+ sSavedEnv = Map.empty,
30−-- The mark must never be equal to noMark!
40+ sMark = noMark + 1, -- The mark must never be equal to noMark!
31−initialState = (Map.empty, emptyPool, noMark + 1, [])
41+ sErrors = []
33−modifyEnv f = modify $ \(env, pool, mark, errors) -> (f env, pool, mark, errors)
43+
34−modifyPool f = modify $ \(env, pool, mark, errors) -> (env, f pool, mark, errors)
44+modifyEnv f = modify $ \state -> state { sEnv = f (sEnv state) }
45+modifyPool f = modify $ \state -> state { sPool = f (sPool state) }
35addError message t1 t2 =
46addError message t1 t2 =
36− modify $ \(env, pool, mark, errors) -> (env, pool, mark, err : errors)
47+ modify $ \state -> state { sErrors = err : sErrors state }
38 wordify = P.fsep . map P.text . words
49 wordify = P.fsep . map P.text . words
39 msg = wordify message
50 msg = wordify message
@@ -53,19 +64,21 @@ addError message t1 t2 =
53switchToPool pool = modifyPool (\_ -> pool)
64switchToPool pool = modifyPool (\_ -> pool)
55getPool :: StateT SolverState IO Pool
66getPool :: StateT SolverState IO Pool
56−getPool = do
67+getPool = sPool <$> get
57− (_, pool, _, _) <- get
60getEnv :: StateT SolverState IO (Map.Map String Variable)
69getEnv :: StateT SolverState IO (Map.Map String Variable)
61−getEnv = do
70+getEnv = sEnv <$> get
62− (env, _, _, _) <- get
71+
63− return env
72+saveLocalEnv :: StateT SolverState IO ()
75+ modify $ \state -> state { sSavedEnv = env }
65uniqueMark :: StateT SolverState IO Int
77uniqueMark :: StateT SolverState IO Int
66uniqueMark = do
78uniqueMark = do
67− (env, pool, mark, errs) <- get
79+ state <- get
80+ let mark = sMark state
68− put (env, pool, mark+1, errs)
81+ put $ state { sMark = mark + 1 }
69 return mark
82 return mark
71nextRankPool :: StateT SolverState IO Pool
84nextRankPool :: StateT SolverState IO Pool