blob: 4338cbd32f2d419cdc20a34ba8e87a0f4c608a75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
Require Import Ltac2.Ltac2 Ltac2.Notations.
Ltac2 Type exn ::= [ Nope ].
Ltac2 check_id id id' := match Ident.equal id id' with
| true => ()
| false => Control.throw Nope
end.
Goal True -> False.
Proof.
Fail
let b := { contents := true } in
let f c :=
match b.(contents) with
| true => Message.print (Message.of_constr c); b.(contents) := false; fail
| false => ()
end
in
(** This fails because the matching is not allowed to backtrack once
it commits to a branch*)
lazy_match! '(nat -> bool) with context [?a] => f a end.
lazy_match! Control.goal () with ?a -> ?b => Message.print (Message.of_constr b) end.
(** This one works by taking the second match context, i.e. ?a := nat *)
let b := { contents := true } in
let f c :=
match b.(contents) with
| true => b.(contents) := false; fail
| false => Message.print (Message.of_constr c)
end
in
match! '(nat -> bool) with context [?a] => f a end.
Abort.
Goal forall (i j : unit) (x y : nat) (b : bool), True.
Proof.
Fail match! goal with
| [ h : ?t, h' : ?t |- _ ] => ()
end.
intros i j x y b.
match! goal with
| [ h : ?t, h' : ?t |- _ ] =>
check_id h @x;
check_id h' @y
end.
match! reverse goal with
| [ h : ?t, h' : ?t |- _ ] =>
check_id h @j;
check_id h' @i
end.
Abort.
(* Check #79 *)
Goal 2 = 3.
Control.plus
(fun ()
=> lazy_match! goal with
| [ |- 2 = 3 ] => Control.zero (Tactic_failure None)
| [ |- 2 = _ ] => Control.zero (Tactic_failure (Some (Message.of_string "should not be printed")))
end)
(fun e
=> match e with
| Tactic_failure c
=> match c with
| None => ()
| _ => Control.zero e
end
| e => Control.zero e
end).
Abort.
|