@@ -871,6 +871,9 @@ updateError ns (CantUnify b (l,lp) (r,rp) e xs sc)
871871 (updateSolvedTerm ns r, fmap (updateProv ns) rp) (updateError ns e) xs sc
872872updateError ns e = e
873873
874+updateRes ns [] = []
875+updateRes ns ((x, t) : ts) = (x, updateSolvedTerm ns t) : updateRes ns ts
876+
874877solveInProblems x val [] = []
875878solveInProblems x val ((l, r, env, err) : ps)
876879 = ((psubst x val l, psubst x val r,
@@ -898,7 +901,15 @@ getProvenance _ = (Nothing, Nothing)
898901updateProblems :: ProofState -> [(Name, TT Name)] -> Fails
899902 -> ([(Name, TT Name)], Fails)
900903-- updateProblems ctxt [] ps inj holes = ([], ps)
901−updateProblems ps updates probs = up updates probs where
904+updateProblems ps updates probs = rec 10 updates probs
905+ where
906+ -- keep trying if we make progress, but not too many times...
907+ rec 0 us fs = (us, fs)
908+ rec n us fs = case up us [] fs of
909+ res@(_, []) -> res
910+ res@(us', _) | length us' == length us -> res
911+ (us', fs') -> rec (n - 1) us' fs'
912+
902913 hs = holes ps
903914 inj = injective ps
904915 ctxt = context ps
@@ -906,8 +917,8 @@ updateProblems ps updates probs = up updates probs where
906917 usupp = map fst (notunified ps)
907918 dont = dontunify ps
908919
909− up ns [] = (ns, [])
910− up ns (prob@(x, y, ready, env, err, while, um) : ps) =
920+ up ns acc [] = (ns, map (updateNs ns) (reverse acc))
921+ up ns acc (prob@(x, y, ready, env, err, while, um) : ps) =
911922 let (x', newx) = updateSolvedTerm' ns x
912923 (y', newy) = updateSolvedTerm' ns y
913924 (lp, rp) = getProvenance err
@@ -918,13 +929,17 @@ updateProblems ps updates probs = up updates probs where
918929 case unify ctxt env' (x', lp) (y', rp) inj hs usupp while of
919930 OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v,dont)) $
920931 let v' = filter (\(n, _) -> n `notElem` dont) v in
921− up (ns ++ v') ps
932+ up (ns ++ v') acc ps
922933 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
923− let (ns', ps') = up ns ps in
924− (ns', (x',y', False, env',err', while, um) : ps')
934+ up ns ((x',y',False,env',err',while,um) : acc) ps
925935 else -- trace ("SKIPPING " ++ show (x,y,ready)) $
926− let (ns', ps') = up ns ps in
927− (ns', (x',y', False, env',err', while, um) : ps')
936+ up ns ((x',y', False, env',err', while, um) : acc) ps
937+
938+ updateNs ns (x, y, t, env, err, fc, fa)
939+ = let (x', newx) = updateSolvedTerm' ns x
940+ (y', newy) = updateSolvedTerm' ns y in
941+ (x', y', newx || newy,
942+ updateEnv ns env, updateError ns err, fc, fa)
928943
929944-- attempt to solve remaining problems with match_unify
930945matchProblems :: Bool -> ProofState -> [(Name, TT Name)] -> Fails
@@ -995,7 +1010,9 @@ processTactic UnifyProblems ps
9951010 previous = Just ps, plog = "",
9961011 notunified = updateNotunified ns' (notunified ps),
9971012 recents = recents ps ++ map fst ns',
1013+ dotted = filter (notIn ns') (dotted ps),
9981014 holes = holes ps \\ (map fst ns') }, plog ps)
1015+ where notIn ns (h, _) = h `notElem` map fst ns
9991016processTactic (MatchProblems all) ps
10001017 = do let (ns', probs') = matchProblems all ps [] (problems ps)
10011018 (ns'', probs'') = matchProblems all ps ns' probs'
@@ -1022,14 +1039,16 @@ processTactic t ps
10221039 let pterm'' = updateSolved ns' (pterm ps')
10231040 traceWhen (unifylog ps)
10241041 ("Updated problems after solve " ++ qshow probs' ++ "\n" ++
1025− "(Toplevel) Dropping holes: " ++ show (map fst ns')) $
1042+ "(Toplevel) Dropping holes: " ++ show (map fst ns') ++ "\n" ++
1043+ "Holes were: " ++ show (holes ps')) $
10261044 return (ps' { pterm = pterm'',
10271045 solved = Nothing,
10281046 problems = probs',
10291047 notunified = updateNotunified ns' (notunified ps'),
10301048 previous = Just ps, plog = "",
10311049 recents = recents ps' ++ map fst ns',
1032− holes = holes ps' \\ (map fst ns')}, plog ps')
1050+ holes = holes ps' \\ (map fst ns')
1051+ }, plog ps')
10331052
10341053process :: Tactic -> Name -> StateT TState TC ()
10351054process EndUnify _