@@ -23,6 +23,7 @@ data ProofState = PS { thname :: Name,
2323 pterm :: Term, -- current proof term
2424 ptype :: Type, -- original goal
2525 unified :: (Name, [(Name, Term)]),
26+ problems :: Fails,
2627 injective :: [(Term, Term, Term)],
2728 deferred :: [Name], -- names we'll need to define
2829 instances :: [Name], -- instance arguments (for type classes)
@@ -69,8 +70,8 @@ data Tactic = Attack
6970-- Some utilites on proof and tactic states
7071
7172instance Show ProofState where
72− show (PS nm [] _ tm _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
73− show (PS nm (h:hs) _ tm _ _ _ i _ _ ctxt _ _)
73+ show (PS nm [] _ tm _ _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
74+ show (PS nm (h:hs) _ tm _ _ _ _ i _ _ ctxt _ _)
7475 = let OK g = goal (Just h) tm
7576 wkenv = premises g in
7677 "Other goals: " ++ show hs ++ "\n" ++
@@ -106,7 +107,10 @@ unify' ctxt env topx topy = do (u, inj, fails) <- lift $ unify ctxt env topx top
106107 addInj inj
107108 case fails of
108109 [] -> return u
109− ((_,_,err):_) -> lift $ tfail err
110+ err ->
111+ do ps <- get
112+ put (ps { problems = err ++ problems ps })
113+ return []
110114
111115getName :: Monad m => String -> StateT TState m Name
112116getName tag = do ps <- get
@@ -124,7 +128,7 @@ addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
124128newProof :: Name -> Context -> Type -> ProofState
125129newProof n ctxt ty = let h = holeName 0
126130 ty' = vToP ty in
127− PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty (h, []) []
131+ PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty (h, []) [] []
128132 [] []
129133 Nothing ctxt "" False
130134
@@ -437,6 +441,12 @@ updateSolved xs (P _ n _)
437441 | Just v <- lookup n xs = v
438442updateSolved xs t = t
439443
444+updateProblems ns [] = []
445+updateProblems ns ((x, y, env, err) : ps) =
446+ let x' = updateSolved ns x
447+ y' = updateSolved ns y in
448+ (x',y',env,err) : updateProblems ns ps
449+
440450processTactic :: Tactic -> ProofState -> TC (ProofState, String)
441451processTactic QED ps = case holes ps of
442452 [] -> do let tm = {- normalise (context ps) [] -} (pterm ps)
@@ -448,13 +458,17 @@ processTactic ProofState ps = return (ps, showEnv [] (pterm ps))
448458processTactic Undo ps = case previous ps of
449459 Nothing -> fail "Nothing to undo."
450460 Just pold -> return (pold, "")
451−processTactic EndUnify ps = let (h, ns) = unified ps
452− tm' = updateSolved ns (pterm ps) in
453− return (ps { pterm = tm',
454− unified = (h, []),
455− injective = map (tmap (updateSolved ns))
456− (injective ps),
457− holes = holes ps \\ map fst ns }, "")
461+processTactic EndUnify ps
462+ = let (h, ns) = unified ps
463+ tm' = updateSolved ns (pterm ps)
464+ probs' = updateProblems ns (problems ps) in
465+ case probs' of
466+ [] -> return (ps { pterm = tm',
467+ unified = (h, []),
468+ injective = map (tmap (updateSolved ns))
469+ (injective ps),
470+ holes = holes ps \\ map fst ns }, "")
471+ errs@((_,_,_,err):_) -> tfail err
458472processTactic (Reorder n) ps
459473 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
460474 return (ps' { previous = Just ps, plog = "" }, plog ps')