@@ -47,21 +47,13 @@ data Tactic = Attack
4747 | CheckIn Raw
4848 | Intro Name
4949 | Forall Name Raw
50− | PatVar Name Raw
50+ | PatVar Name
5151 | Focus Name
5252 | MoveLast Name
5353 | ProofState
5454 | Undo
5555 | QED
5656
57−data TacticAction = AddGoal Name -- add a new goal, solve immediately
58− | NextGoal Name -- add a new goal, solve it after current one
59− | FocusGoal Name -- focus on this goal next
60− | MoveGoal Name -- move this goal to the end of the hole queue
61− | Solved Name
62− | AlsoSolved [(Name, Term)] -- variables solved by unification
63− | Log String
64−
6557-- Some utilites on proof and tactic states
6658
6759instance Show ProofState where
@@ -69,21 +61,22 @@ instance Show ProofState where
6961 show (PS nm (h:hs) _ tm _ _ i _ ctxt _ _)
7062 = let OK g = goal (Just h) tm
7163 wkenv = premises g in
64+ "Other goals: " ++ show hs ++ "\n" ++
7265 showPs wkenv (reverse wkenv) ++ "\n" ++
7366 "-------------------------------- (" ++ show nm ++
74− ") -------\n" ++
67+ ") -------\n " ++
7568 show h ++ " : " ++ showG wkenv (goalType g) ++ "\n"
7669 where showPs env [] = ""
7770 showPs env ((n, Let t v):bs)
7871 = " " ++ show n ++ " : " ++
79− showEnv env (normalise ctxt env t) ++ " = " ++
80− showEnv env (normalise ctxt env v) ++
72+ showEnv env ({- normalise ctxt env -} t) ++ " = " ++
73+ showEnv env ({- normalise ctxt env -} v) ++
8174 "\n" ++ showPs env bs
8275 showPs env ((n, b):bs)
8376 = " " ++ show n ++ " : " ++
84− showEnv env (normalise ctxt env (binderTy b)) ++
77+ showEnv env ({- normalise ctxt env -} (binderTy b)) ++
8578 "\n" ++ showPs env bs
86− showG ps (Guess t v) = showEnv ps (normalise ctxt ps t) ++
79+ showG ps (Guess t v) = showEnv ps ({- normalise ctxt ps -} t) ++
8780 " =?= " ++ showEnv ps v
8881 showG ps b = showEnv ps (binderTy b)
8982
@@ -211,14 +204,14 @@ fill guess ctxt env (Bind x (Hole ty) sc) =
211204 ps <- get
212205 let (uh, uns) = unified ps
213206 put (ps { unified = (uh, uns ++ ns) })
214− addLog (show (uh, uns ++ ns))
207+-- addLog (show (uh, uns ++ ns))
215208 return $ Bind x (Guess ty val) sc
216209fill _ _ _ _ = fail "Can't fill here."
217210
218211solve :: RunTactic
219212solve ctxt env (Bind x (Guess ty val) sc)
220213 | pureTerm val = do action (\ps -> ps { holes = holes ps \\ [x] })
221− return $ Bind x (Let ty val) sc -- instantiate val (pToV x sc)
214+ return $ {- Bind x (Let ty val) sc -} instantiate val (pToV x sc)
222215 | otherwise = fail "I see a hole in your solution."
223216solve _ _ _ = fail "Not a guess."
224217
@@ -238,11 +231,10 @@ forall n ty ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
238231 lift $ isSet ctxt env t
239232 return $ Bind n (Pi tyv) (Bind x (Hole t) (P Bound x t))
240233
241−patvar :: Name -> Raw -> RunTactic
242−patvar n ty ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
243− do (tyv, tyt) <- lift $ check ctxt env ty
244− lift $ isSet ctxt env tyt
245− return $ Bind n (PVar tyv) (Bind x (Hole t) (P Bound x t))
234+patvar :: Name -> RunTactic
235+patvar n ctxt env (Bind x (Hole t) sc) =
236+ do action (\ps -> ps { holes = holes ps \\ [x] })
237+ return $ Bind n (PVar t) (instantiate (P Bound n t) (pToV x sc))
246238
247239compute :: RunTactic
248240compute ctxt env (Bind x (Hole ty) sc) =
@@ -276,9 +268,10 @@ solve_unified ctxt env tm =
276268 do ps <- get
277269 let (_, ns) = unified ps
278270 action (\ps -> ps { holes = holes ps \\ map fst ns })
271+-- action (\ps -> ps { pterm = updateSolved ns (pterm ps) })
279272 return (updateSolved ns tm)
280273 where
281− updateSolved xs (Bind n b@(Hole _) t)
274+ updateSolved xs (Bind n (Hole ty) t)
282275 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved xs t))
283276 updateSolved xs (Bind n b t)
284277 | otherwise = Bind n (fmap (updateSolved xs) b) (updateSolved xs t)
@@ -295,7 +288,7 @@ solve_unified ctxt env tm =
295288
296289processTactic :: Tactic -> ProofState -> TC (ProofState, String)
297290processTactic QED ps = case holes ps of
298− [] -> do let tm = pterm ps
291+ [] -> do let tm = {- normalise (context ps) [] -} (pterm ps)
299292 (tm', ty') <- recheck (context ps) [] tm
300293 return (ps { done = True, pterm = tm' },
301294 "Proof complete: " ++ showEnv [] tm')
@@ -304,6 +297,20 @@ processTactic ProofState ps = return (ps, showEnv [] (pterm ps))
304297processTactic Undo ps = case previous ps of
305298 Nothing -> Error "Nothing to undo."
306299 Just pold -> return (pold, "")
300+processTactic EndUnify ps = let (h, ns) = unified ps
301+ tm' = updateSolved ns (pterm ps) in
302+ return (ps { pterm = tm',
303+ unified = (h, []),
304+ holes = holes ps \\ map fst ns }, "")
305+ where
306+ updateSolved xs (Bind n (Hole ty) t)
307+ | Just v <- lookup n xs = instantiate v (pToV n (updateSolved xs t))
308+ updateSolved xs (Bind n b t)
309+ | otherwise = Bind n (fmap (updateSolved xs) b) (updateSolved xs t)
310+ updateSolved xs (App f a) = App (updateSolved xs f) (updateSolved xs a)
311+ updateSolved xs (P _ n _)
312+ | Just v <- lookup n xs = v
313+ updateSolved xs t = t
307314processTactic t ps
308315 = case holes ps of
309316 [] -> Error "Nothing to fill in."
@@ -327,7 +334,7 @@ process t h = tactic (Just h) (mktac t)
327334 mktac Compute = compute
328335 mktac (Intro n) = intro n
329336 mktac (Forall n t) = forall n t
330− mktac (PatVar n t) = patvar n t
337+ mktac (PatVar n) = patvar n
331338 mktac (CheckIn r) = check_in r
332339 mktac (EvalIn r) = eval_in r
333340 mktac (Focus n) = focus n