Debian Codegraph @

test-suite/output/Notations2.v

raw
1 (**********************************************************************)
2 (* Test call to primitive printers in presence of coercion to *)
3 (* functions (cf bug #2044) *)
4
5 Inductive PAIR := P (n1:nat) (n2:nat).
6 Coercion P : nat >-> Funclass.
7 Check (2 3).
8
9 (* Check that notations with coercions to functions inserted still work *)
10 (* (were not working from revision 11886 to 12951) *)
11
12 Record Binop := { binop :> nat -> nat -> nat }.
13 Class Plusop := { plusop : Binop; zero : nat }.
14 Infix "[+]" := plusop (at level 40).
15 #[global]
16 Instance Plus : Plusop := {| plusop := {| binop := plus |} ; zero := 0 |}.
17 Check 2[+]3.
18
19 (* Test bug #2091 (variable le was printed using <= !) *)
20
21 Check forall (A: Set) (le: A -> A -> Prop) (x y: A), le x y \/ le y x.
22
23 (* Test recursive notations in cases pattern *)
24
25 Remove Printing Let prod.
26 Check match (0,0,0) with (x,y,z) => x+y+z end.
27 Check let '(a,b,c) := ((2,3),4) in a.
28
29 (* Check printing of notations with mixed reserved binders (see bug #2571) *)
30
31 Implicit Type myx : bool.
32 Check exists myx y, myx = y.
33
34 (* Test notation for anonymous functions up to eta-expansion *)
35
36 Check fun P:nat->nat->Prop => fun x:nat => ex (P x).
37
38 (* Test notations with binders *)
39
40 Notation "∃ x .. y , P":= (ex (fun x => .. (ex (fun y => P)) ..))
41 (x binder, y binder, at level 200, right associativity,
42 format "'[ ' ∃ x .. y ']' , P").
43
44 Check (∃ n p, n+p=0).
45
46 Check ∃ (a:=0) (x:nat) y (b:=1) (c:=b) (d:=2) z (e:=3) (f:=4), x+y = z+d.
47
48 Notation "∀ x .. y , P":= (forall x, .. (forall y, P) ..)
49 (x binder, at level 200, right associativity).
50
51 Check (∀ n p, n+p=0).
52
53 Notation "'λ' x .. y , P":= (fun x => .. (fun y => P) ..)
54 (y binder, at level 200, right associativity).
55
56 Check (λ n p, n+p=0).
57
58 Generalizable Variable A.
59
60 Check `(λ n p : A, n=p).
61 Check `(∃ n p : A, n=p).
62 Check `(∀ n p : A, n=p).
63
64 Notation "'let'' f x .. y := t 'in' u":=
65 (let f := fun x => .. (fun y => t) .. in u)
66 (f name, x closed binder, y closed binder, at level 200,
67 right associativity).
68
69 Check let' f x y (a:=0) z (b:bool) := x+y+z+1 in f 0 1 2.
70
71 (* In practice, only the printing rule is used here *)
72 (* Note: does not work for pattern *)
73 Module A.
74 #[warning="-postfix-notation-not-level-1"]
75 Notation "f ( x )" := (f x) (at level 10, format "f ( x )").
76 Check fun f x => f x + S x.
77
78 Open Scope list_scope.
79 Abbreviation list1 := (1::nil)%list.
80 Abbreviation plus2 n := (S (S n)).
81 (* plus2 was not correctly printed in the two following tests in 8.3pl1 *)
82 Print plus2.
83 Check fun n => match n with list1 => 0 | _ => 2 end.
84 Unset Printing Allow Match Default Clause.
85 Check fun n => match n with list1 => 0 | _ => 2 end.
86 Unset Printing Factorizable Match Patterns.
87 Check fun n => match n with list1 => 0 | _ => 2 end.
88 Set Printing Allow Match Default Clause.
89 Set Printing Factorizable Match Patterns.
90
91 End A.
92
93 (* This one is not fully satisfactory because binders in the same type
94 are re-factorized and parentheses are needed even for atomic binder
95
96 Notation "'mylet' f [ x ; .. ; y ] := t 'in' u":=
97 (let f := fun x => .. (fun y => t) .. in u)
98 (f name, x closed binder, y closed binder, at level 200,
99 right associativity).
100
101 Check mylet f [x;y;z;(a:bool)] := x+y+z+1 in f 0 1 2.
102 *)
103
104 (* Check notations for functional terms which do not necessarily
105 depend on their parameter *)
106 (* Old request mentioned again on coq-club 20/1/2012 *)
107
108 Notation "# x : T => t" := (fun x : T => t)
109 (at level 2, t at level 200, x name).
110
111 Check # x : nat => x.
112 Check # _ : nat => 2.
113
114 (* Check bug 4677 *)
115 Check fun x (H:le x 0) => exist (le x) 0 H.
116
117 Parameters (A : Set) (x y : A) (Q : A -> A -> Prop) (conj : Q x y).
118 Check (exist (Q x) y conj).
119
120 (* Check bug #4854 *)
121 Notation "% i" := (fun i : nat => i) (at level 2, i name).
122 Check %i.
123 Check %j.
124
125 (* Check bug raised on coq-club on Sep 12, 2016 *)
126
127 Notation "{ x , y , .. , v }" := (fun a => (or .. (or (a = x) (a = y)) .. (a = v))).
128 Check ({1, 2}).
129
130 (**********************************************************************)
131 (* Check notations of the form ".a", ".a≡", "a≡" *)
132 (* Only "a#", "a≡" and ".≡" were working properly for parsing. The *)
133 (* other ones were working only for printing. *)
134
135 Notation "a#" := nat.
136 Check nat.
137 Check a#.
138
139 Notation "a≡" := nat.
140 Check nat.
141 Check a≡.
142
143 Notation ".≡" := nat.
144 Check nat.
145 Check .≡.
146
147 Notation ".a#" := nat.
148 Check nat.
149 Check .a#.
150
151 Notation ".a≡" := nat.
152 Check nat.
153 Check .a≡.
154
155 Notation ".α" := nat.
156 Check nat.
157 Check .α.
158
159 (* A test for #6304 *)
160
161 Module M6304.
162 Notation "'for' m 'from' 0 'to' N 'updating' ( s1 ) {{ b }} ;; rest" :=
163 (let s1 :=
164 (fix rec(n: nat) := match n with
165 | 0 => s1
166 | S m => let s1 := rec m in b
167 end) N
168 in rest)
169 (at level 20).
170
171 Check fun (a b : nat) =>
172 let res := 0 in
173 for i from 0 to a updating (res) {{
174 for j from 0 to b updating (res) {{ S res }};;
175 res
176 }};; res.
177
178 End M6304.