@@ -4,7 +4,7 @@
4 proofs, and some high level commands for introducing new theorems,
4 proofs, and some high level commands for introducing new theorems,
5 evaluation/checking inside the proof system, etc. --}
5 evaluation/checking inside the proof system, etc. --}
7−module ProofState(ProofState(..), newProof, envAtFocus,
7+module ProofState(ProofState(..), newProof, envAtFocus, goalAtFocus,
8 Tactic(..), processTactic) where
8 Tactic(..), processTactic) where
10import Typecheck
10import Typecheck
@@ -42,13 +42,14 @@ data Tactic = Attack
42 | Intro Name
42 | Intro Name
43 | Forall Name Raw
43 | Forall Name Raw
44 | Focus Name
44 | Focus Name
45 | ProofState
46 | ProofState
47−-- Next: add 'EvalHere' and 'CheckHere' tactics
49data TacticAction = AddGoal Name -- add a new goal, solve immediately
49data TacticAction = AddGoal Name -- add a new goal, solve immediately
50 | NextGoal Name -- add a new goal, solve it after current one
50 | NextGoal Name -- add a new goal, solve it after current one
51 | FocusGoal Name -- focus on this goal next
51 | FocusGoal Name -- focus on this goal next
52+ | MoveGoal Name -- move this goal to the end of the hole queue
52 | Solved Name
53 | Solved Name
53 | AlsoSolved Name Term -- goals solved by unification
54 | AlsoSolved Name Term -- goals solved by unification
54 | Log String
55 | Log String
@@ -111,6 +112,11 @@ envAtFocus ps
111 return (premises g)
112 return (premises g)
112 | otherwise = fail "No holes"
113 | otherwise = fail "No holes"
115+goalAtFocus :: ProofState -> TC Type
117+ | not $ null (holes ps) = do g <- goal (Just (head (holes ps))) (pterm ps)
118+ return (binderTy (goalType g))
114goal :: Hole -> Term -> TC Goal
120goal :: Hole -> Term -> TC Goal
115goal h tm = g [] tm where
121goal h tm = g [] tm where
116 g env (Bind n b sc) | hole b && same h n = return $ GD env b
122 g env (Bind n b sc) | hole b && same h n = return $ GD env b
@@ -160,6 +166,10 @@ focus :: Name -> RunTactic
160focus n ctxt env t = do action (FocusGoal n)
166focus n ctxt env t = do action (FocusGoal n)
161 return t
167 return t
169+movelast :: Name -> RunTactic
170+movelast n ctxt env t = do action (MoveGoal n)
163-- Hmmm. YAGNI?
173-- Hmmm. YAGNI?
164regret :: RunTactic
174regret :: RunTactic
165regret = undefined
175regret = undefined
@@ -257,6 +267,7 @@ processTactic t ps
257 goals g (AddGoal n : xs) = goals (n : g) xs
267 goals g (AddGoal n : xs) = goals (n : g) xs
258 goals (g:gs) (NextGoal n : xs) = goals (g : n : gs) xs
268 goals (g:gs) (NextGoal n : xs) = goals (g : n : gs) xs
259 goals g (FocusGoal n : xs) = goals (n : (g \\ [n])) xs
269 goals g (FocusGoal n : xs) = goals (n : (g \\ [n])) xs
270+ goals g (MoveGoal n : xs) = goals ((g \\ [n]) ++ [n]) xs
260 goals g (Solved n : xs) = goals (g \\ [n]) xs
271 goals g (Solved n : xs) = goals (g \\ [n]) xs
261 goals g (AlsoSolved n tm : xs) = goals (g \\ [n]) xs
272 goals g (AlsoSolved n tm : xs) = goals (g \\ [n]) xs
262 goals g (_ : xs) = goals g xs
273 goals g (_ : xs) = goals g xs
@@ -265,8 +276,9 @@ processTactic t ps
265 getSolved (AlsoSolved n tm : xs) = (n, tm) : getSolved xs
276 getSolved (AlsoSolved n tm : xs) = (n, tm) : getSolved xs
266 getSolved (_ : xs) = getSolved xs
277 getSolved (_ : xs) = getSolved xs
268− updateSolved xs (Bind n b t)
279+ updateSolved xs (Bind n b@(Hole _) t)
269 | Just v <- lookup n xs = Bind n (Let (binderTy b) v) (updateSolved xs t)
280 | Just v <- lookup n xs = Bind n (Let (binderTy b) v) (updateSolved xs t)
281+ updateSolved xs (Bind n b t)
270 | otherwise = Bind n (fmap (updateSolved xs) b) (updateSolved xs t)
282 | otherwise = Bind n (fmap (updateSolved xs) b) (updateSolved xs t)
271 updateSolved xs (App f a) = App (updateSolved xs f) (updateSolved xs a)
283 updateSolved xs (App f a) = App (updateSolved xs f) (updateSolved xs a)
272 updateSolved xs t = t
284 updateSolved xs t = t
@@ -285,3 +297,4 @@ process t h ps = tactic (Just h) ps (context ps) (mktac t)
285 mktac (CheckIn r) = check_in r
297 mktac (CheckIn r) = check_in r
286 mktac (EvalIn r) = eval_in r
298 mktac (EvalIn r) = eval_in r
287 mktac (Focus n) = focus n
299 mktac (Focus n) = focus n
300+ mktac (MoveLast n) = movelast n