@@ -50,6 +50,7 @@ data Tactic = Attack
50 | Intro Name
50 | Intro Name
51 | Forall Name Raw
51 | Forall Name Raw
52 | LetBind Name Raw Raw
52 | LetBind Name Raw Raw
53 | PatVar Name
54 | PatVar Name
54 | PatBind Name
55 | PatBind Name
55 | Focus Name
56 | Focus Name
@@ -280,6 +281,31 @@ letbind n ty val ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
280 return $ Bind n (Let tyv valv) (Bind x (Hole t) (P Bound x t))
281 return $ Bind n (Let tyv valv) (Bind x (Hole t) (P Bound x t))
281letbind n ty val ctxt env _ = fail "Can't let bind here"
282letbind n ty val ctxt env _ = fail "Can't let bind here"
284+rewrite :: Raw -> RunTactic
285+rewrite tm ctxt env (Bind x (Hole t) xp@(P _ x' _)) | x == x' =
286+ do (tmv, tmt) <- lift $ check ctxt env tm
288+ (P _ (UN ["="]) _, [lt,rt,l,r]) ->
289+ do let p = Bind rname (Lam lt) (mkP (P Bound rname lt) r l t)
290+ let newt = mkP l r l t
291+ return (Bind x (Hole newt)
292+ (mkApp (P Ref (UN ["replace"]) (Set 0))
293+ [lt, l, r, p, tmv, xp]))
294+ -- fail $ "Rewrite " ++ show l ++ " to " ++ show r ++ " in " ++
295+ -- show t ++ " with " ++ show (p, newt) ++ " not done yet"
296+ _ -> fail "Not an equality type"
298+ -- to make the P for rewrite, replace syntactic occurrences of l in ty with
299+ -- and x, and put \x : lt in front
300+ mkP lt l r ty | l == ty = lt
301+ mkP lt l r (App f a) = let f' = if (r /= f) then mkP lt l r f else f
302+ a' = if (r /= a) then mkP lt l r a else a in
306+ rname = MN 0 "replaced"
307+rewrite _ _ _ _ = fail "Can't rewrite here"
283patbind :: Name -> RunTactic
309patbind :: Name -> RunTactic
284patbind n ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
310patbind n ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
285 do let t' = normalise ctxt env t
311 do let t' = normalise ctxt env t
@@ -390,6 +416,7 @@ process t h = tactic (Just h) (mktac t)
390 mktac (Intro n) = intro n
416 mktac (Intro n) = intro n
391 mktac (Forall n t) = forall n t
417 mktac (Forall n t) = forall n t
392 mktac (LetBind n t v) = letbind n t v
418 mktac (LetBind n t v) = letbind n t v
419+ mktac (Rewrite t) = rewrite t
393 mktac (PatVar n) = patvar n
420 mktac (PatVar n) = patvar n
394 mktac (PatBind n) = patbind n
421 mktac (PatBind n) = patbind n
395 mktac (CheckIn r) = check_in r
422 mktac (CheckIn r) = check_in r