Debian Codegraph @

test-suite/output/PatternsInBinders.v

raw
1 (** The purpose of this file is to test printing of the destructive
2 patterns used in binders ([fun] and [forall]). *)
3
4 Parameters (A B : Type) (P:A->Prop).
5
6 Definition swap '((x,y) : A*B) := (y,x).
7 Print swap.
8
9 Check fun '((x,y) : A*B) => (y,x).
10
11 Check forall '(x,y), swap (x,y) = (y,x).
12
13 Definition proj_informative '(exist _ x _ : { x:A | P x }) : A := x.
14 Print proj_informative.
15
16 Inductive Foo := Bar : nat -> bool -> unit -> nat -> Foo.
17 Definition foo '(Bar n b tt p) :=
18 if b then n+p else n-p.
19 Print foo.
20
21 Definition baz '(Bar n1 b1 tt p1) '(Bar n2 b2 tt p2) := n1+p1.
22 Print baz.
23
24 Module WithParameters.
25
26 Definition swap {A B} '((x,y) : A*B) := (y,x).
27 Print swap.
28
29 Check fun (A B:Type) '((x,y) : A*B) => swap (x,y) = (y,x).
30 Check forall (A B:Type) '((x,y) : A*B), swap (x,y) = (y,x).
31
32 Check exists '((x,y):A*A), swap (x,y) = (y,x).
33 Check exists '((x,y):A*A) '(z,w), swap (x,y) = (z,w).
34
35 End WithParameters.
36
37 (** Some test involving unicode notations. *)
38 Module WithUnicode.
39
40 Check fun '((x,y) : A*B) => (y,x).
41 Check forall '(x,y), swap (x,y) = (y,x).
42
43 End WithUnicode.
44
45 (** * Suboptimal printing *)
46
47 Module Suboptimal.
48
49 (** This test shows an example which exposes the [let] introduced by
50 the pattern notation in binders. *)
51
52 Inductive Fin (n:nat) := Z : Fin n.
53 Definition F '(n,p) : Type := (Fin n * Fin p)%type.
54 Definition both_z '(n,p) : F (n,p) := (Z _,Z _).
55 Print both_z.
56
57 (** Test factorization of binders *)
58
59 Check fun '((x,y) : A*B) '(z,t) => swap (x,y) = (z,t).
60 Check forall '(x,y) '((z,t) : B*A), swap (x,y) = (z,t).
61
62 End Suboptimal.
63
64 (** Test risk of collision for internal name *)
65 Check fun pat => fun '(x,y) => x+y = pat.
66
67 (** Test name in degenerate case *)
68 Definition f 'x := x+x.
69 Print f.
70 Check fun 'x => x+x.