@@ -36,11 +36,13 @@ data ProofState = PS { thname :: Name,
3636 injective :: [Name],
3737 deferred :: [Name], -- names we'll need to define
3838 instances :: [Name], -- instance arguments (for type classes)
39+ autos :: [(Name, [Name])], -- unsolved 'auto' implicits with their holes
3940 previous :: Maybe ProofState, -- for undo
4041 context :: Context,
4142 plog :: String,
4243 unifylog :: Bool,
4344 done :: Bool,
45+ recents :: [Name],
4446 while_elaborating :: [FailContext]
4547 }
4648
@@ -78,6 +80,7 @@ data Tactic = Attack
7880 | Defer [Name] Name
7981 | DeferType Name Raw [Name]
8082 | Instance Name
83+ | AutoArg Name
8184 | SetInjective Name
8285 | MoveLast Name
8386 | MatchProblems Bool
@@ -90,9 +93,9 @@ data Tactic = Attack
9093-- Some utilites on proof and tactic states
9194
9295instance Show ProofState where
93− show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
96+ show (PS nm [] _ _ tm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
9497 = show nm ++ ": no more goals"
95− show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _)
98+ show (PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ _ ctxt _ _ _ _ _)
9699 = let OK g = goal (Just h) tm
97100 wkenv = premises g in
98101 "Other goals: " ++ show hs ++ "\n" ++
@@ -115,9 +118,9 @@ instance Show ProofState where
115118 showG ps b = showEnv ps (binderTy b)
116119
117120instance Pretty ProofState OutputAnnotation where
118− pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
121+ pretty (PS nm [] _ _ trm _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) =
119122 pretty nm <+> colon <+> text " no more goals."
120− pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ ctxt _ _ _ _) =
123+ pretty p@(PS nm (h:hs) _ _ tm _ _ _ _ _ _ _ i _ _ _ ctxt _ _ _ _ _) =
121124 let OK g = goal (Just h) tm in
122125 let wkEnv = premises g in
123126 text "Other goals" <+> colon <+> pretty hs <+>
@@ -285,8 +288,8 @@ newProof n ctxt ty = let h = holeName 0
285288 PS n [h] [] 1 (mkProofTerm (Bind h (Hole ty')
286289 (P Bound h ty'))) ty [] (h, []) []
287290 Nothing [] []
288− [] []
289− Nothing ctxt "" False False []
291+ [] [] []
292+ Nothing ctxt "" False False [] []
290293
291294type TState = ProofState -- [TacticAction])
292295type RunTactic = RunTactic' TState
@@ -381,6 +384,16 @@ instanceArg n ctxt env (Bind x (Hole t) sc)
381384 instances = x:is })
382385 return (Bind x (Hole t) sc)
383386
387+autoArg :: Name -> RunTactic
388+autoArg n ctxt env (Bind x (Hole t) sc)
389+ = do action (\ps -> case lookup x (autos ps) of
390+ Nothing ->
391+ let hs = holes ps in
392+ ps { holes = (hs \\ [x]) ++ [x],
393+ autos = (x, refsIn t) : autos ps }
394+ Just _ -> ps)
395+ return (Bind x (Hole t) sc)
396+
384397setinj :: Name -> RunTactic
385398setinj n ctxt env (Bind x b sc)
386399 = do action (\ps -> let is = injective ps in
@@ -494,6 +507,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
494507 solved = Just (x, val),
495508 notunified = updateNotunified [(x,val)]
496509 (notunified ps),
510+ recents = x : recents ps,
497511 instances = instances ps \\ [x] })
498512 let tm' = subst x val sc in
499513 return tm'
@@ -647,7 +661,8 @@ casetac tm induction ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' = do
647661 consargs' <- query (\ps -> map (flip (uniqueNameCtxt (context ps)) (holes ps ++ allTTNames (getProofTerm (pterm ps))) *** uniqueBindersCtxt (context ps) (holes ps ++ allTTNames (getProofTerm (pterm ps)))) consargs)
648662 let res = flip (foldr substV) params $ (substV prop $ bindConsArgs consargs' (mkApp (P Ref (SN (tacn tnm)) (TType (UVal 0)))
649663 (params ++ [prop] ++ map makeConsArg consargs' ++ indicies ++ [tmv])))
650− action (\ps -> ps {holes = holes ps \\ [x]})
664+ action (\ps -> ps {holes = holes ps \\ [x],
665+ recents = x : recents ps })
651666 mapM_ addConsHole (reverse consargs')
652667 let res' = forget $ res
653668 (scv, sct) <- lift $ check ctxt env res'
@@ -739,7 +754,8 @@ solve_unified ctxt env tm =
739754 let (_, ns) = unified ps
740755 let unify = dropGiven (dontunify ps) ns (holes ps)
741756 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping holes " ++ show (map fst unify)) $
742− holes ps \\ map fst unify })
757+ holes ps \\ map fst unify,
758+ recents = recents ps ++ map fst unify })
743759 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
744760 return (updateSolvedTerm unify tm)
745761
@@ -858,11 +874,13 @@ processTactic EndUnify ps
858874 unified = (h, []),
859875 problems = probs',
860876 notunified = updateNotunified ns'' (notunified ps),
877+ recents = recents ps ++ map fst ns'',
861878 holes = holes ps \\ map fst ns'' }, "")
862879processTactic UnifyAll ps
863880 = let tm' = updateSolved (notunified ps) (pterm ps) in
864881 return (ps { pterm = tm',
865882 notunified = [],
883+ recents = recents ps ++ map fst (notunified ps),
866884 holes = holes ps \\ map fst (notunified ps) }, "")
867885processTactic (Reorder n) ps
868886 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
@@ -882,6 +900,7 @@ processTactic UnifyProblems ps
882900 return (ps { pterm = pterm', solved = Nothing, problems = probs',
883901 previous = Just ps, plog = "",
884902 notunified = updateNotunified ns' (notunified ps),
903+ recents = recents ps ++ map fst ns',
885904 holes = holes ps \\ (map fst ns') }, plog ps)
886905processTactic (MatchProblems all) ps
887906 = let (ns', probs') = matchProblems all [] (context ps)
@@ -897,6 +916,7 @@ processTactic (MatchProblems all) ps
897916 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
898917 previous = Just ps, plog = "",
899918 notunified = updateNotunified ns'' (notunified ps),
919+ recents = recents ps ++ map fst ns'',
900920 holes = holes ps \\ (map fst ns'') }, plog ps)
901921processTactic t ps
902922 = case holes ps of
@@ -921,6 +941,7 @@ processTactic t ps
921941 problems = probs',
922942 notunified = updateNotunified ns' (notunified ps'),
923943 previous = Just ps, plog = "",
944+ recents = recents ps' ++ map fst ns',
924945 holes = holes ps' \\ (map fst ns')}, plog ps')
925946
926947process :: Tactic -> Name -> StateT TState TC ()
@@ -959,5 +980,6 @@ process t h = tactic (Just h) (mktac t)
959980 mktac (Defer ns n) = defer ns n
960981 mktac (DeferType n t a) = deferType n t a
961982 mktac (Instance n) = instanceArg n
983+ mktac (AutoArg n) = autoArg n
962984 mktac (SetInjective n) = setinj n
963985 mktac (MoveLast n) = movelast n