@@ -34,6 +34,7 @@ data Command = Theorem Name Raw
34data Tactic = Attack
34data Tactic = Attack
35 | Claim Name Raw
35 | Claim Name Raw
36 | Fill Raw
36 | Fill Raw
@@ -49,6 +50,7 @@ data TacticAction = AddGoal Name -- add a new goal, solve immediately
49 | NextGoal Name -- add a new goal, solve it after current one
50 | NextGoal Name -- add a new goal, solve it after current one
50 | FocusGoal Name -- focus on this goal next
51 | FocusGoal Name -- focus on this goal next
51 | Solved Name
52 | Solved Name
53+ | AlsoSolved Name Term -- goals solved by unification
52 | Log String
54 | Log String
54-- Some utilites on proof and tactic states
56-- Some utilites on proof and tactic states
@@ -162,6 +164,20 @@ fill guess ctxt env (Bind x (Hole ty) sc) =
162 return $ Bind x (Guess ty val) sc
164 return $ Bind x (Guess ty val) sc
163fill _ _ _ _ = fail "Can't fill here."
165fill _ _ _ _ = fail "Can't fill here."
167+-- As fill, but attempts to solve other goals by unification
169+unify_fill :: Raw -> RunTactic
170+unify_fill guess ctxt env (Bind x (Hole ty) sc) =
171+ do (val, valty) <- lift $ check ctxt env guess
172+ ns <- lift $ unify ctxt env valty ty
174+ return $ Bind x (Guess ty val) sc
176+ solve_all [] = return ()
177+ solve_all ((n, tm): ns) = do action (AlsoSolved n tm)
179+unify_fill _ _ _ _ = fail "Can't fill here."
165solve :: RunTactic
181solve :: RunTactic
166solve ctxt env (Bind x (Guess ty val) sc)
182solve ctxt env (Bind x (Guess ty val) sc)
167 | pureTerm val = do action (Solved x)
183 | pureTerm val = do action (Solved x)
@@ -209,13 +225,15 @@ processTactic QED ps = case holes ps of
209 "Proof complete: " ++ showEnv [] tm)
225 "Proof complete: " ++ showEnv [] tm)
210 _ -> Error "Still holes to fill."
226 _ -> Error "Still holes to fill."
211processTactic ProofState ps = return (ps, showEnv [] (pterm ps))
227processTactic ProofState ps = return (ps, showEnv [] (pterm ps))
212−processTactic t ps = case holes ps of
228+processTactic t ps
213− [] -> Error "Nothing to fill in."
230+ [] -> Error "Nothing to fill in."
214− (h:_) -> do let n = nextname ps
231+ (h:_) -> do let n = nextname ps
215− (ps',(n', actions)) <- runStateT (process t h ps) (n, [])
232+ (ps', (n', actions)) <- runStateT (process t h ps) (n, [])
216− return (ps' { nextname = n',
233+ return (ps' { nextname = n',
234+ pterm = updateSolved (getSolved actions) (pterm ps'),
217− holes = goals (holes ps') actions },
235+ holes = goals (holes ps') actions },
218− logs actions)
236+ logs actions)
219 where logs [] = ""
237 where logs [] = ""
220 logs (Log x : xs) = x ++ "\n" ++ logs xs
238 logs (Log x : xs) = x ++ "\n" ++ logs xs
221 logs (_ : xs) = logs xs
239 logs (_ : xs) = logs xs
@@ -225,18 +243,31 @@ processTactic t ps = case holes ps of
225 goals (g:gs) (NextGoal n : xs) = goals (g : n : gs) xs
243 goals (g:gs) (NextGoal n : xs) = goals (g : n : gs) xs
226 goals g (FocusGoal n : xs) = goals (n : (g \\ [n])) xs
244 goals g (FocusGoal n : xs) = goals (n : (g \\ [n])) xs
227 goals g (Solved n : xs) = goals (g \\ [n]) xs
245 goals g (Solved n : xs) = goals (g \\ [n]) xs
246+ goals g (AlsoSolved n tm : xs) = goals (g \\ [n]) xs
228 goals g (_ : xs) = goals g xs
247 goals g (_ : xs) = goals g xs
250+ getSolved (AlsoSolved n tm : xs) = (n, tm) : getSolved xs
251+ getSolved (_ : xs) = getSolved xs
253+ updateSolved xs (Bind n b t)
254+ | Just v <- lookup n xs = Bind n (Let (binderTy b) v) (updateSolved xs t)
255+ | otherwise = Bind n (fmap (updateSolved xs) b) (updateSolved xs t)
256+ updateSolved xs (App f a) = App (updateSolved xs f) (updateSolved xs a)
257+ updateSolved xs t = t
231process :: Tactic -> Name -> ProofState -> StateT TState TC ProofState
261process :: Tactic -> Name -> ProofState -> StateT TState TC ProofState
232process t h ps = tactic (Just h) ps (context ps) (mktac t)
262process t h ps = tactic (Just h) ps (context ps) (mktac t)
233− where mktac Attack = attack
263+ where mktac Attack = attack
234− mktac (Claim n r) = claim n r
264+ mktac (Claim n r) = claim n r
235− mktac (Fill r) = fill r
265+ mktac (Fill r) = fill r
266+ mktac (UnifyFill r) = unify_fill r
236− mktac Regret = regret
267+ mktac Regret = regret
237− mktac Solve = solve
268+ mktac Solve = solve
238− mktac Compute = compute
269+ mktac Compute = compute
239− mktac (Intro n) = intro n
270+ mktac (Intro n) = intro n
240− mktac (CheckIn r) = check_in r
271+ mktac (CheckIn r) = check_in r
241− mktac (EvalIn r) = eval_in r
272+ mktac (EvalIn r) = eval_in r
242− mktac (Focus n) = focus n
273+ mktac (Focus n) = focus n