Debian Codegraph @

test-suite/output/Notations.v

raw
1 (* Bug 5568, don't warn for notations in repeated module import *)
2
3 Module foo.
4 Abbreviation compose := (fun g f => g f).
5 Notation "g & f" := (compose g f) (at level 10).
6 End foo.
7
8 Import foo.
9 Import foo.
10 Import foo.
11
12 (**********************************************************************)
13 (* Notations for if and let (submitted by Roland Zumkeller) *)
14
15 Notation "a ? b ; c" := (if a then b else c) (at level 10).
16
17 Check (true ? 0 ; 1).
18 Check if true as x return (if x then nat else bool) then 0 else true.
19
20 Notation "'proj1' t" := (let (a,_) := t in a) (at level 1).
21
22 Check (fun e : nat * nat => proj1 e).
23
24 Notation "'decomp' a 'as' x , y 'in' b" := (let (x,y) := a in b) (at level 1).
25
26 Check (decomp (true,true) as t, u in (t,u)).
27
28 (**********************************************************************)
29 (* Behaviour wrt to binding variables (submitted by Roland Zumkeller) *)
30
31 Section A.
32
33 Notation "! A" := (forall _:nat, A) (at level 60).
34
35 Check ! (0=0).
36 Check forall n, n=0.
37 Check forall n:nat, 0=0.
38
39 End A.
40
41 (**********************************************************************)
42 (* Behaviour wrt to binding variables (cf bug report #1186) *)
43
44 Section B.
45
46 Notation "# A" := (forall n:nat, n=n->A) (at level 60).
47 Check forall n:nat, # (n=n).
48
49 Notation "## A" := (forall n n0:nat, n=n0->A) (at level 60).
50 Check forall n n0:nat, ## (n=n0).
51
52 Notation "### A" :=
53 (forall n n0:nat, match n with O => True | S n => n=n0 end ->A) (at level 60).
54 Check forall n n0:nat, ### (n=n0).
55
56 End B.
57
58 (**********************************************************************)
59 (* Check recursive notations *)
60
61 Notation "[ x ; .. ; y ]" := (cons x .. (cons y nil) ..).
62 Check [1;2;4].
63
64 Reserved Notation "( x ; y , .. , z )" (at level 0).
65 Notation "( x ; y , .. , z )" := (pair .. (pair x y) .. z).
66 Check (1;2,4).
67
68 (* Check basic notations involving "match" *)
69
70 Section C.
71
72 Notation "'ifzero' n" := (match n with 0 => true | S _ => false end)
73 (at level 2, n at level 0).
74 Check (ifzero 3).
75
76 Notation "'pred' n" := (match n with 0 => 0 | S n' => n' end)
77 (at level 2, n at level 0).
78 Check (pred 3).
79 Check (fun n => match n with 0 => 0 | S n => n end).
80 Check (fun n => match n with S p as x => p | _ => 0 end).
81
82 Notation "'ifn' x 'is' 'succ' n 'then' t 'else' u" :=
83 (match x with O => u | S n => t end) (at level 2, u at level 0).
84 Check fun x => ifn x is succ n then n else 0.
85
86 End C.
87
88 (* Check correction of bug #1179 *)
89
90 Notation "1 -" := true (at level 0).
91 Check 1-.
92
93 (**********************************************************************)
94 (* Check ill-formed recursive notations *)
95
96 (* Recursive variables not part of a recursive pattern *)
97 Fail Notation "( x , y , .. , z )" := (pair x .. (pair y z) ..).
98
99 (* No recursive notation *)
100 Fail Notation "( x , y , .. , z )" := (pair x (pair y z)).
101
102 (* Left-unbound variable *)
103 Fail Notation "( x , y , .. , z )" := (pair x .. (pair y w) ..).
104
105 (* Right-unbound variable *)
106 Notation "( x , y , .. , z )" := (pair y .. (pair z 0) ..) (only parsing).
107
108 (* Not the right kind of recursive pattern *)
109 Fail Notation "( x , y , .. , z )" := (ex (fun z => .. (ex (fun y => x)) ..)).
110 Fail Notation "( x -- y , .. , z )" := (pair y .. (pair z 0) ..)
111 (y closed binder, z closed binder).
112
113 (* No separator allowed with open binders *)
114 Fail Notation "( x -- y , .. , z )" := (ex (fun z => .. (ex (fun y => x)) ..))
115 (y binder, z binder).
116
117 (* Ends of pattern do not match *)
118 Fail Notation "( x , y , .. , z )" := (pair y .. (pair (plus z) 0) ..).
119 Fail Notation "( x , y , .. , z )" := (pair y .. (plus z 0) ..).
120 Fail Notation "( x1 , x2 , y , .. , z )" := (y y .. (x2 z 0) ..).
121 Fail Notation "( x1 , x2 , y , .. , z )" := (x1 y .. (x2 z 0) ..).
122
123 (* Ends of pattern are the same *)
124 Fail Notation "( x , y , .. , z )" := (pair .. (pair (pair y z) x) .. x).
125
126 (**********************************************************************)
127 (* Check preservation of scopes at printing time *)
128
129 Abbreviation SUM := sum.
130 Check SUM (nat*nat) nat.
131
132 (**********************************************************************)
133 (* Check preservation of implicit arguments at printing time *)
134
135 Abbreviation FST := fst.
136 Check FST (0;1).
137
138 (**********************************************************************)
139 (* Check notations for references with activated or deactivated *)
140 (* implicit arguments *)
141
142 Abbreviation Nil := @nil.
143 Check Nil.
144
145 Abbreviation NIL := nil.
146 Check NIL : list nat.
147
148
149 (**********************************************************************)
150 (* Test printing of notation with coercions in scope of a coercion *)
151
152 Open Scope nat_scope.
153
154 Coercion is_true := fun b => b=true.
155 Coercion of_nat n := match n with 0 => true | _ => false end.
156 Notation "'I' x" := (of_nat (S x) || true)%bool (at level 10).
157
158 Check (false && I 3)%bool /\ I 6.
159
160 (**********************************************************************)
161 (* Check notations with several recursive patterns *)
162
163 Notation "[| x , y , .. , z ; a , b , .. , c |]" :=
164 (pair (pair .. (pair x y) .. z) (pair .. (pair a b) .. c)).
165 Check [|1,2,3;4,5,6|].
166
167 Notation "[| t * ( x , y , .. , z ) ; ( a , b , .. , c ) * u |]" :=
168 (pair (pair .. (pair (pair t x) (pair t y)) .. (pair t z))
169 (pair .. (pair (pair a u) (pair b u)) .. (pair c u)))
170 (t at level 39).
171 Check [|0*(1,2,3);(4,5,6)*false|].
172
173 (**********************************************************************)
174 (* Test recursive notations involving applications *)
175
176 Module Application.
177
178 Notation "{| f ; x ; .. ; y |}" := ( .. (f x) .. y).
179
180 (* Application to a variable *)
181
182 Check fun f => {| f; 0; 1; 2 |} : nat.
183
184 (* Application to a fun *)
185
186 Check {| (fun x => x+x); 0 |}.
187
188 (* Application to a reference *)
189
190 Axiom op : nat -> nat -> nat.
191 Check {| op; 0; 1 |}.
192
193 (* Interaction with coercion *)
194
195 Axiom c : nat -> bool.
196 Coercion c : nat >-> bool.
197 Check false = {| c; 0 |}.
198
199 End Application.
200
201 (* Check notations in cases patterns *)
202
203 Abbreviation SOME := Some.
204 Abbreviation NONE := None.
205 Check (fun x => match x with SOME x => x | NONE => 0 end).
206
207 Abbreviation NONE2 := (@None _).
208 Abbreviation SOME2 := (@Some _).
209 Check (fun x => match x with SOME2 x => x | NONE2 => 0 end).
210
211 Abbreviation NONE3 := @None.
212 Abbreviation SOME3 := @Some.
213 Check (fun x => match x with SOME3 _ x => x | NONE3 _ => 0 end).
214
215 Notation "a :'" := (cons a) (at level 1).
216
217 Check (fun x => match x with | nil => NONE | h :' t => SOME3 _ t end).
218
219 (* Check correct matching of "Type" in notations. Of course the
220 notation denotes a term that will be reinterpreted with a different
221 universe than the actual one; but it would be the same anyway
222 without a notation *)
223
224 Abbreviation s := Type.
225 Check s.
226
227 (* Test bug #2835: notations were not uniformly managed under prod and lambda *)
228
229 Open Scope nat_scope.
230
231 Notation "'foo' n" := (S n) (at level 50): nat_scope.
232
233 Check (foo 9).
234 Check (fun _ : nat => 9).
235
236 (* Checking parsing and printing of numerical and non-numerical notations for eq_refl *)
237
238 (* This notation was not correctly printed until Pierre B.'s
239 improvements to the interpretation of patterns *)
240
241 Notation "'ONE'" := eq_refl.
242 Check fun (x:nat) (p : x=x) => match p with ONE => ONE end = p.
243
244 (* This one used to failed at parsing until now *)
245
246 Notation "1" := eq_refl.
247 Check fun (x:nat) (p : x=x) => match p with 1 => 1 end = p.
248
249 (* Check bug 5693 *)
250
251 Module M.
252 Definition A := 0.
253 Definition bar (a b : nat) := plus a b.
254 Notation "" := A (format "", only printing).
255 Check (bar A 0).
256 End M.
257
258 (* Check eq notations *)
259 Module EqNotationsCheck.
260 Import EqNotations.
261 Section nd.
262 Context (A : Type) (x : A) (P : A -> Type)
263 (y : A) (p : x = y) (v : P x) (v' : P y).
264
265 Check let k : P y := rew p in v in k.
266 Check let k : P y := rew -> p in v in k.
267 Check let k : P x := rew <- p in v' in k.
268 Check let k : P y := rew [P] p in v in k.
269 Check let k : P y := rew -> [P] p in v in k.
270 Check let k : P x := rew <- [P] p in v' in k.
271 Check let k : P y := rew [fun y => P y] p in v in k.
272 Check let k : P y := rew -> [fun y => P y] p in v in k.
273 Check let k : P x := rew <- [fun y => P y] p in v' in k.
274 Check let k : P y := rew [fun (y : A) => P y] p in v in k.
275 Check let k : P y := rew -> [fun (y : A) => P y] p in v in k.
276 Check let k : P x := rew <- [fun (y : A) => P y] p in v' in k.
277 End nd.
278 Section dep.
279 Context (A : Type) (x : A) (P : forall y, x = y -> Type)
280 (y : A) (p : x = y) (P' : forall x, y = x -> Type)
281 (v : P x eq_refl) (v' : P' y eq_refl).
282
283 Check let k : P y p := rew dependent p in v in k.
284 Check let k : P y p := rew dependent -> p in v in k.
285 Check let k : P' x (eq_sym p) := rew dependent <- p in v' in k.
286 Check let k : P y p := rew dependent [P] p in v in k.
287 Check let k : P y p := rew dependent -> [P] p in v in k.
288 Check let k : P' x (eq_sym p) := rew dependent <- [P'] p in v' in k.
289 Check let k : P y p := rew dependent [fun y p => P y p] p in v in k.
290 Check let k : P y p := rew dependent -> [fun y p => P y p] p in v in k.
291 Check let k : P' x (eq_sym p) := rew dependent <- [fun y p => P' y p] p in v' in k.
292 Check let k : P y p := rew dependent [fun y p => id (P y p)] p in v in k.
293 Check let k : P y p := rew dependent -> [fun y p => id (P y p)] p in v in k.
294 Check let k : P' x (eq_sym p) := rew dependent <- [fun y p => id (P' y p)] p in v' in k.
295 Check let k : P y p := rew dependent [(fun (y : A) (p : x = y) => P y p)] p in v in k.
296 Check let k : P y p := rew dependent -> [(fun (y : A) (p : x = y) => P y p)] p in v in k.
297 Check let k : P' x (eq_sym p) := rew dependent <- [(fun (x : A) (p : y = x) => P' x p)] p in v' in k.
298 Check let k : P y p := rew dependent [(fun (y : A) (p : x = y) => id (P y p))] p in v in k.
299 Check let k : P y p := rew dependent -> [(fun (y : A) (p : x = y) => id (P y p))] p in v in k.
300 Check let k : P' x (eq_sym p) := rew dependent <- [(fun (x : A) (p : y = x) => id (P' x p))] p in v' in k.
301 Check match p as x in _ = a return P a x with
302 | eq_refl => v
303 end.
304 Check match eq_sym p as p' in _ = a return P' a p' with
305 | eq_refl => v'
306 end.
307 Check match p as x in _ = a return id (P a x) with
308 | eq_refl => v
309 end.
310 Check match eq_sym p as p' in _ = a return id (P' a p') with
311 | eq_refl => v'
312 end.
313 End dep.
314 End EqNotationsCheck.