@@ -180,6 +180,19 @@ match_unify' ctxt env topx topy =
180-- -- ++ show (pterm ps)
180-- -- ++ show (pterm ps)
181-- ++ "\n----------") $
181-- ++ "\n----------") $
183+mergeSolutions :: Env -> [(Name, TT Name)] -> StateT TState TC [(Name, TT Name)]
184+mergeSolutions env ns = merge [] ns
186+ merge acc [] = return (reverse acc)
187+ merge acc ((n, t) : ns)
188+ | Just t' <- lookup n ns
190+ let probs = problems ps
191+ put (ps { problems = probs ++ [(t,t',env,Msg "New problem",
194+ | otherwise = merge ((n, t): acc) ns
183unify' :: Context -> Env -> TT Name -> TT Name ->
196unify' :: Context -> Env -> TT Name -> TT Name ->
184 StateT TState TC [(Name, TT Name)]
197 StateT TState TC [(Name, TT Name)]
185unify' ctxt env topx topy =
198unify' ctxt env topx topy =
@@ -206,17 +219,22 @@ unify' ctxt env topx topy =
206 ++ "\nCurrent problems:\n" ++ qshow (problems ps)
219 ++ "\nCurrent problems:\n" ++ qshow (problems ps)
207-- ++ show (pterm ps)
220-- ++ show (pterm ps)
208 ++ "\n----------") $
221 ++ "\n----------") $
210− let (h, ns) = unified ps
222+ do let (h, ns) = unified ps
223+ -- if a metavar has multiple solutions, make a new unification
224+ -- problem for each.
225+ uns <- mergeSolutions env (u ++ ns)
211− let (ns', probs') = updateProblems (context ps) (u ++ ns)
227+ let (ns', probs') = updateProblems (context ps) uns
212 (fails ++ problems ps)
228 (fails ++ problems ps)
213 (injective ps)
229 (injective ps)
214 (holes ps)
230 (holes ps)
215 let (notu', probs_notu) = mergeNotunified env (notu ++ notunified ps)
231 let (notu', probs_notu) = mergeNotunified env (notu ++ notunified ps)
232+ traceWhen (unifylog ps)
233+ ("Now solved: " ++ show ns') $
216− put (ps { problems = probs' ++ probs_notu,
234+ put (ps { problems = probs' ++ probs_notu,
217− unified = (h, ns'),
235+ unified = (h, ns'),
218− injective = updateInj u (injective ps),
236+ injective = updateInj u (injective ps),
219− notunified = notu' })
237+ notunified = notu' })
221 where updateInj ((n, a) : us) inj
239 where updateInj ((n, a) : us) inj
222 | (P _ n' _, _) <- unApply a,
240 | (P _ n' _, _) <- unApply a,