@@ -23,6 +23,7 @@ data ProofState = PS { thname :: Name,
23 pterm :: Term, -- current proof term
23 pterm :: Term, -- current proof term
24 ptype :: Type, -- original goal
24 ptype :: Type, -- original goal
25 unified :: (Name, [(Name, Term)]),
25 unified :: (Name, [(Name, Term)]),
26+ injective :: [(Term, Term, Term)],
26 deferred :: [Name], -- names we'll need to define
27 deferred :: [Name], -- names we'll need to define
27 instances :: [Name], -- instance arguments (for type classes)
28 instances :: [Name], -- instance arguments (for type classes)
28 previous :: Maybe ProofState, -- for undo
29 previous :: Maybe ProofState, -- for undo
@@ -68,8 +69,8 @@ data Tactic = Attack
68-- Some utilites on proof and tactic states
69-- Some utilites on proof and tactic states
70instance Show ProofState where
71instance Show ProofState where
71− show (PS nm [] _ tm _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
72+ show (PS nm [] _ tm _ _ _ _ _ _ _ _ _) = show nm ++ ": no more goals"
72− show (PS nm (h:hs) _ tm _ _ i _ _ ctxt _ _)
73+ show (PS nm (h:hs) _ tm _ _ _ i _ _ ctxt _ _)
73 = let OK g = goal (Just h) tm
74 = let OK g = goal (Just h) tm
74 wkenv = premises g in
75 wkenv = premises g in
75 "Other goals: " ++ show hs ++ "\n" ++
76 "Other goals: " ++ show hs ++ "\n" ++
@@ -116,7 +117,7 @@ addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
116newProof :: Name -> Context -> Type -> ProofState
117newProof :: Name -> Context -> Type -> ProofState
117newProof n ctxt ty = let h = holeName 0
118newProof n ctxt ty = let h = holeName 0
118 ty' = vToP ty in
119 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, []) []
121 Nothing ctxt "" False
122 Nothing ctxt "" False
@@ -243,6 +244,10 @@ defer n ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
243regret :: RunTactic
244regret :: RunTactic
244regret = undefined
245regret = undefined
247+addInj :: [(Term, Term, Term)] -> StateT TState TC ()
248+addInj inj = do ps <- get
249+ put (ps { injective = inj ++ injective ps })
246exact :: Raw -> RunTactic
251exact :: Raw -> RunTactic
247exact guess ctxt env (Bind x (Hole ty) sc) =
252exact guess ctxt env (Bind x (Hole ty) sc) =
248 do (val, valty) <- lift $ check ctxt env guess
253 do (val, valty) <- lift $ check ctxt env guess
@@ -256,7 +261,8 @@ fill :: Raw -> RunTactic
256fill guess ctxt env (Bind x (Hole ty) sc) =
261fill guess ctxt env (Bind x (Hole ty) sc) =
257 do (val, valty) <- lift $ check ctxt env guess
262 do (val, valty) <- lift $ check ctxt env guess
259− ns <- lift $ unify ctxt env valty ty
264+ (ns, inj) <- lift $ unify ctxt env valty ty
260 ps <- get
266 ps <- get
261 let (uh, uns) = unified ps
267 let (uh, uns) = unified ps
262 put (ps { unified = (uh, uns ++ ns) })
268 put (ps { unified = (uh, uns ++ ns) })
@@ -274,7 +280,8 @@ complete_fill :: RunTactic
274complete_fill ctxt env (Bind x (Guess ty val) sc) =
280complete_fill ctxt env (Bind x (Guess ty val) sc) =
275 do let guess = forget val
281 do let guess = forget val
276 (val', valty) <- lift $ check ctxt env guess
282 (val', valty) <- lift $ check ctxt env guess
277− ns <- lift $ unify ctxt env valty ty
283+ (ns, inj) <- lift $ unify ctxt env valty ty
278 ps <- get
285 ps <- get
279 let (uh, uns) = unified ps
286 let (uh, uns) = unified ps
280 put (ps { unified = (uh, uns ++ ns) })
287 put (ps { unified = (uh, uns ++ ns) })
@@ -302,7 +309,8 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
302-- ns <- lift $ unify ctxt env tyv t'
309-- ns <- lift $ unify ctxt env tyv t'
303 case t' of
310 case t' of
304 Bind y (Pi s) t -> let t' = instantiate (P Bound n s) (pToV y t) in
311 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
306 ps <- get
314 ps <- get
307 let (uh, uns) = unified ps
315 let (uh, uns) = unified ps
308 put (ps { unified = (uh, uns ++ ns) })
316 put (ps { unified = (uh, uns ++ ns) })
@@ -405,12 +413,15 @@ start_unify :: Name -> RunTactic
405start_unify n ctxt env tm = do action (\ps -> ps { unified = (n, []) })
413start_unify n ctxt env tm = do action (\ps -> ps { unified = (n, []) })
406 return tm
414 return tm
416+tmap f (a, b, c) = (f a, b, c)
408solve_unified :: RunTactic
418solve_unified :: RunTactic
409solve_unified ctxt env tm =
419solve_unified ctxt env tm =
410 do ps <- get
420 do ps <- get
411 let (_, ns) = unified ps
421 let (_, ns) = unified ps
412 action (\ps -> ps { holes = holes ps \\ map fst ns })
422 action (\ps -> ps { holes = holes ps \\ map fst ns })
413 action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
423 action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
424+ action (\ps -> ps { injective = map (tmap (updateSolved ns)) (injective ps) })
414 return (updateSolved ns tm)
425 return (updateSolved ns tm)
416updateSolved xs (Bind n (Hole ty) t)
427updateSolved xs (Bind n (Hole ty) t)
@@ -437,6 +448,8 @@ processTactic EndUnify ps = let (h, ns) = unified ps
437 tm' = updateSolved ns (pterm ps) in
448 tm' = updateSolved ns (pterm ps) in
438 return (ps { pterm = tm',
449 return (ps { pterm = tm',
439 unified = (h, []),
450 unified = (h, []),
451+ injective = map (tmap (updateSolved ns))
440 holes = holes ps \\ map fst ns }, "")
453 holes = holes ps \\ map fst ns }, "")
441processTactic (Reorder n) ps
454processTactic (Reorder n) ps
442 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
455 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps