@@ -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+ injective :: [(Term, Term, Term)],
2627 deferred :: [Name], -- names we'll need to define
2728 instances :: [Name], -- instance arguments (for type classes)
2829 previous :: Maybe ProofState, -- for undo
@@ -68,8 +69,8 @@ data Tactic = Attack
6869-- Some utilites on proof and tactic states
6970
7071instance Show ProofState where
71− show (PS nm [] _ tm _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
72− show (PS nm (h:hs) _ tm _ _ i _ _ ctxt _ _)
72+ show (PS nm [] _ tm _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
73+ show (PS nm (h:hs) _ tm _ _ _ i _ _ ctxt _ _)
7374 = let OK g = goal (Just h) tm
7475 wkenv = premises g in
7576 "Other goals: " ++ show hs ++ "\n" ++
@@ -116,7 +117,7 @@ addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
116117newProof :: Name -> Context -> Type -> ProofState
117118newProof n ctxt ty = let h = holeName 0
118119 ty' = vToP ty in
119− PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty (h, [])
120+ PS n [h] 1 (Bind h (Hole ty') (P Bound h ty')) ty (h, []) []
120121 [] []
121122 Nothing ctxt "" False
122123
@@ -243,6 +244,10 @@ defer n ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
243244regret :: RunTactic
244245regret = undefined
245246
247+addInj :: [(Term, Term, Term)] -> StateT TState TC ()
248+addInj inj = do ps <- get
249+ put (ps { injective = inj ++ injective ps })
250+
246251exact :: Raw -> RunTactic
247252exact guess ctxt env (Bind x (Hole ty) sc) =
248253 do (val, valty) <- lift $ check ctxt env guess
@@ -256,7 +261,8 @@ fill :: Raw -> RunTactic
256261fill guess ctxt env (Bind x (Hole ty) sc) =
257262 do (val, valty) <- lift $ check ctxt env guess
258263 s <- get
259− ns <- lift $ unify ctxt env valty ty
264+ (ns, inj) <- lift $ unify ctxt env valty ty
265+ addInj inj
260266 ps <- get
261267 let (uh, uns) = unified ps
262268 put (ps { unified = (uh, uns ++ ns) })
@@ -274,7 +280,8 @@ complete_fill :: RunTactic
274280complete_fill ctxt env (Bind x (Guess ty val) sc) =
275281 do let guess = forget val
276282 (val', valty) <- lift $ check ctxt env guess
277− ns <- lift $ unify ctxt env valty ty
283+ (ns, inj) <- lift $ unify ctxt env valty ty
284+ addInj inj
278285 ps <- get
279286 let (uh, uns) = unified ps
280287 put (ps { unified = (uh, uns ++ ns) })
@@ -302,7 +309,8 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
302309-- ns <- lift $ unify ctxt env tyv t'
303310 case t' of
304311 Bind y (Pi s) t -> let t' = instantiate (P Bound n s) (pToV y t) in
305− do ns <- lift $ unify ctxt env s tyv
312+ do (ns, inj) <- lift $ unify ctxt env s tyv
313+ addInj inj
306314 ps <- get
307315 let (uh, uns) = unified ps
308316 put (ps { unified = (uh, uns ++ ns) })
@@ -405,12 +413,15 @@ start_unify :: Name -> RunTactic
405413start_unify n ctxt env tm = do action (\ps -> ps { unified = (n, []) })
406414 return tm
407415
416+tmap f (a, b, c) = (f a, b, c)
417+
408418solve_unified :: RunTactic
409419solve_unified ctxt env tm =
410420 do ps <- get
411421 let (_, ns) = unified ps
412422 action (\ps -> ps { holes = holes ps \\ map fst ns })
413423 action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
424+ action (\ps -> ps { injective = map (tmap (updateSolved ns)) (injective ps) })
414425 return (updateSolved ns tm)
415426
416427updateSolved xs (Bind n (Hole ty) t)
@@ -437,6 +448,8 @@ processTactic EndUnify ps = let (h, ns) = unified ps
437448 tm' = updateSolved ns (pterm ps) in
438449 return (ps { pterm = tm',
439450 unified = (h, []),
451+ injective = map (tmap (updateSolved ns))
452+ (injective ps),
440453 holes = holes ps \\ map fst ns }, "")
441454processTactic (Reorder n) ps
442455 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps