aboutsummaryrefslogtreecommitdiffhomepage
path: root/test-suite/success/PatternsInBinders.v
blob: 7771079158f455c443d6b66d72c6860b46f5a5c9 (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
(** The purpose of this file is to test functional properties of the
    destructive patterns used in binders ([fun] and [forall]). *)


Definition swap {A B} '((x,y) : A*B) := (y,x).

(** Tests the use of patterns in [fun] and [Definition] *)
Section TestFun.

  Variables A B : Type.

  Goal forall (x:A) (y:B), swap (x,y) = (y,x).
  Proof. reflexivity. Qed.

  Goal forall u:A*B, swap (swap u) = u.
  Proof. destruct u. reflexivity. Qed.

  Goal @swap A B = fun '(x,y) => (y,x).
  Proof. reflexivity. Qed.

End TestFun.


(** Tests the use of patterns in [forall] *)
Section TestForall.

  Variables A B : Type.

  Goal forall '((x,y) : A*B), swap (x,y) = (y,x).
  Proof. intros [x y]. reflexivity. Qed.

  Goal forall x0:A, exists '((x,y) : A*A), swap (x,y) = (x,y).
  Proof.
    intros x0.
    exists (x0,x0).
    reflexivity.
  Qed.

End TestForall.



(** Tests the use of patterns in dependent definitions. *)

Section TestDependent.

  Inductive Fin (n:nat) := Z : Fin n.

  Definition F '(n,p) : Type := (Fin n * Fin p)%type.

  Definition both_z '(n,p) : F (n,p) := (Z _,Z _).

End TestDependent.


(** Tests with a few other types just to make sure parsing is
    robust. *)
Section TestExtra.

  Definition proj_informative {A P} '(exist _ x _ : { x:A | P x }) : A := x.

  Inductive Foo := Bar : nat -> bool -> unit -> nat -> Foo.

  Definition foo '(Bar n b tt p) :=
    if b then n+p else n-p.

End TestExtra.