| 1 |
(* An example with constr subentries *) |
| 2 |
|
| 3 |
Module A. |
| 4 |
|
| 5 |
Declare Custom Entry myconstr. |
| 6 |
|
| 7 |
Notation "[ x ]" := x (x custom myconstr at level 6). |
| 8 |
Notation "x + y" := (Nat.add x y) (in custom myconstr at level 5). |
| 9 |
Notation "x * y" := (Nat.mul x y) (in custom myconstr at level 4). |
| 10 |
Notation "< x >" := x (in custom myconstr at level 0, x constr at level 10). |
| 11 |
Check [ < 0 > + < 1 > * < 2 >]. |
| 12 |
Print Custom Grammar myconstr. |
| 13 |
|
| 14 |
Axiom a : nat. |
| 15 |
Abbreviation b := a. |
| 16 |
Check [ < b > + < a > * < 2 >]. |
| 17 |
|
| 18 |
Declare Custom Entry anotherconstr. |
| 19 |
|
| 20 |
Notation "[ x ]" := x (x custom myconstr at level 6). |
| 21 |
Notation "<< x >>" := x (in custom myconstr at level 0, x custom anotherconstr at level 10). |
| 22 |
Notation "# x" := (Some x) (in custom anotherconstr at level 8, x constr at level 9). |
| 23 |
Check [ << # 0 >> ]. |
| 24 |
|
| 25 |
(* Now check with global *) |
| 26 |
|
| 27 |
Axiom c : nat. |
| 28 |
Notation "x" := x (in custom myconstr at level 0, x global). |
| 29 |
Check [ b + c ]. |
| 30 |
Check fun a => [ a + a ]. |
| 31 |
|
| 32 |
Module NonCoercions. |
| 33 |
|
| 34 |
(* Should we forbid extra coercions in constr (knowing the "( x )" is hard-wiree)? *) |
| 35 |
Notation "[[ x ]]" := x (at level 0, x at level 42). |
| 36 |
|
| 37 |
(* Check invalid coercions (thus not used for printing) *) |
| 38 |
Notation "[[[ x ]]]" := x (in custom myconstr at level 0, x custom myconstr at level 0). |
| 39 |
|
| 40 |
End NonCoercions. |
| 41 |
|
| 42 |
End A. |
| 43 |
|
| 44 |
Module B. |
| 45 |
|
| 46 |
Inductive Expr := |
| 47 |
| Mul : Expr -> Expr -> Expr |
| 48 |
| Add : Expr -> Expr -> Expr |
| 49 |
| One : Expr. |
| 50 |
|
| 51 |
Declare Custom Entry expr. |
| 52 |
Notation "[ expr ]" := expr (expr custom expr at level 3). |
| 53 |
Notation "1" := One (in custom expr at level 0). |
| 54 |
Notation "x y" := (Mul x y) (in custom expr at level 1, left associativity). |
| 55 |
Notation "x + y" := (Add x y) (in custom expr at level 2, left associativity). |
| 56 |
Notation "( x )" := x (in custom expr at level 0, x at level 3). |
| 57 |
Notation "{ x }" := x (in custom expr at level 0, x constr). |
| 58 |
Notation "x" := x (in custom expr at level 0, x ident). |
| 59 |
|
| 60 |
Axiom f : nat -> Expr. |
| 61 |
Check [1 {f 1}]. |
| 62 |
Check fun x y z => [1 + y z + {f x}]. |
| 63 |
Check fun e => match e with |
| 64 |
| [x y + z] => [x + y z] |
| 65 |
| [1 + 1] => [1] |
| 66 |
| y => [y + e] |
| 67 |
end. |
| 68 |
|
| 69 |
End B. |
| 70 |
|
| 71 |
Module C. |
| 72 |
|
| 73 |
Inductive Expr := |
| 74 |
| Add : Expr -> Expr -> Expr |
| 75 |
| One : Expr. |
| 76 |
|
| 77 |
Notation "[ expr ]" := expr (expr custom expr at level 1). |
| 78 |
Notation "1" := One (in custom expr at level 0). |
| 79 |
Notation "x + y" := (Add x y) (in custom expr at level 2, left associativity). |
| 80 |
Notation "( x )" := x (in custom expr at level 0, x at level 2). |
| 81 |
|
| 82 |
(* Check the use of a two-steps coercion from constr to expr 1 then |
| 83 |
from expr 0 to expr 2 *) |
| 84 |
|
| 85 |
Check [(1 + 1)]. |
| 86 |
|
| 87 |
End C. |
| 88 |
|
| 89 |
(* Fixing overparenthesizing reported by G. Gonthier in #9207 (PR #9214, in 8.10)*) |
| 90 |
|
| 91 |
Module I. |
| 92 |
|
| 93 |
Definition myAnd A B := A /\ B. |
| 94 |
Abbreviation myAnd1 A := (myAnd A). |
| 95 |
Check myAnd1 True True. |
| 96 |
|
| 97 |
Set Warnings "-auto-template". |
| 98 |
|
| 99 |
Record Pnat := {inPnat :> nat -> Prop}. |
| 100 |
Axiom r : nat -> Pnat. |
| 101 |
Check r 2 3. |
| 102 |
|
| 103 |
End I. |
| 104 |
|
| 105 |
Require Import PrimInt63. |
| 106 |
Module NumberNotations. |
| 107 |
Module Test17. |
| 108 |
(** Test uint63 *) |
| 109 |
Declare Scope test17_scope. |
| 110 |
Delimit Scope test17_scope with test17. |
| 111 |
Local Set Primitive Projections. |
| 112 |
Record myint63 := of_int { to_int : int }. |
| 113 |
Definition parse x := |
| 114 |
match x with Pos x => Some (of_int x) | Neg _ => None end. |
| 115 |
Definition print x := Pos (to_int x). |
| 116 |
Number Notation myint63 parse print : test17_scope. |
| 117 |
Check let v := 0%test17 in v : myint63. |
| 118 |
End Test17. |
| 119 |
End NumberNotations. |
| 120 |
|
| 121 |
Module K. |
| 122 |
|
| 123 |
Notation "# x |-> t & u" := ((fun x => (x,t)),(fun x => (x,u))) |
| 124 |
(at level 2, x pattern, t, u at level 39). |
| 125 |
Check fun y : nat => # (x,z) |-> y & y. |
| 126 |
Check fun y : nat => # (x,z) |-> (x + y) & (y + z). |
| 127 |
|
| 128 |
End K. |
| 129 |
|
| 130 |
Module EmptyRecordSyntax. |
| 131 |
|
| 132 |
Record R := { n : nat }. |
| 133 |
Check fun '{|n:=x|} => true. |
| 134 |
|
| 135 |
End EmptyRecordSyntax. |
| 136 |
|
| 137 |
Module M. |
| 138 |
|
| 139 |
(* Accept boxes around the end variables of a recursive notation (if equal boxes) *) |
| 140 |
|
| 141 |
Notation " {@ T1 ; T2 ; .. ; Tn } " := |
| 142 |
(and T1 (and T2 .. (and Tn True)..)) |
| 143 |
(format "'[v' {@ '[' T1 ']' ; '//' '[' T2 ']' ; '//' .. ; '//' '[' Tn ']' } ']'"). |
| 144 |
|
| 145 |
Fail Notation " {@ T1 ; T2 ; .. ; Tn } " := |
| 146 |
(and T1 (and T2 .. (and Tn True)..)) |
| 147 |
(format "'[v' {@ '[' T1 ']' ; '//' '[' T2 ']' ; '//' .. ; '//' '[' Tn ']' } ']'"). |
| 148 |
|
| 149 |
Fail Notation " {@ T1 ; T2 ; .. ; Tn } " := |
| 150 |
(and T1 (and T2 .. (and Tn True)..)) |
| 151 |
(format "'[v' {@ '[' T1 ']' ; '//' '[' T2 ']' ; '//' .. ; '//' '[v' Tn ']' } ']'"). |
| 152 |
|
| 153 |
Fail Notation " {@ T1 ; T2 ; .. ; Tn } " := |
| 154 |
(and T1 (and T2 .. (and Tn True)..)) |
| 155 |
(format "'[v' {@ '[' T1 ']' ; '//' '[' T2 ']' ; '//' .. ; '//' '[' Tn ']' } ']'"). |
| 156 |
|
| 157 |
Fail Notation " {@ T1 ; T2 ; .. ; Tn } " := |
| 158 |
(and T1 (and T2 .. (and Tn True)..)) |
| 159 |
(format "'[v' {@ '[' T1 ']' ; '//' '[' T2 ']' ; '//' .. ; '//' '[' Tn ']' } ']'"). |
| 160 |
|
| 161 |
End M. |
| 162 |
|
| 163 |
Module Bug11331. |
| 164 |
|
| 165 |
Notation "{ p }" := (p) (in custom expr at level 0, p constr). |
| 166 |
Print Custom Grammar expr. |
| 167 |
|
| 168 |
End Bug11331. |
| 169 |
|
| 170 |
Module Bug_6082. |
| 171 |
|
| 172 |
Declare Scope foo. |
| 173 |
Notation "[ x ]" := (S x) (format "[ x ]") : foo. |
| 174 |
Open Scope foo. |
| 175 |
Check fun x => S x. |
| 176 |
|
| 177 |
Declare Scope bar. |
| 178 |
Notation "[ x ]" := (S x) (format "[ x ]") : bar. |
| 179 |
Open Scope bar. |
| 180 |
|
| 181 |
Check fun x => S x. |
| 182 |
|
| 183 |
End Bug_6082. |
| 184 |
|
| 185 |
Module Bug_7766. |
| 186 |
|
| 187 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 188 |
(at level 200, x binder, y binder, right associativity, |
| 189 |
format "'[ ' ∀ x .. y ']' , P") : type_scope. |
| 190 |
|
| 191 |
Check forall (x : nat), x = x. |
| 192 |
|
| 193 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 194 |
(at level 200, x binder, y binder, right associativity, |
| 195 |
format "∀ x .. y , P") : type_scope. |
| 196 |
|
| 197 |
Check forall (x : nat), x = x. |
| 198 |
|
| 199 |
End Bug_7766. |
| 200 |
|
| 201 |
Module N. |
| 202 |
|
| 203 |
(* Other tests about generic and specific formats *) |
| 204 |
|
| 205 |
Reserved Notation "x %%% y" (format "x %%% y", at level 35). |
| 206 |
Reserved Notation "x %%% y" (format "x %%% y", at level 35). |
| 207 |
|
| 208 |
(* Not using the reserved format, we warn *) |
| 209 |
|
| 210 |
Notation "x %%% y" := (x+y) (format "x %%% y", at level 35). |
| 211 |
|
| 212 |
(* Same scope (here lonely): we warn *) |
| 213 |
|
| 214 |
Notation "x %%%% y" := (x+y) (format "x %%%% y", at level 35). |
| 215 |
Notation "x %%%% y" := (x+y) (format "x %%%% y", at level 35). |
| 216 |
|
| 217 |
(* Test if the format for a specific notation becomes the default |
| 218 |
generic format or if the generic format, in the absence of a |
| 219 |
Reserved Notation, is the one canonically obtained from the |
| 220 |
notation *) |
| 221 |
|
| 222 |
Declare Scope foo_scope. |
| 223 |
Declare Scope bar_scope. |
| 224 |
Declare Scope bar'_scope. |
| 225 |
Notation "x %% y" := (x+y) (at level 47, format "x %% y") : foo_scope. |
| 226 |
Open Scope foo_scope. |
| 227 |
Check 3 %% 4. |
| 228 |
|
| 229 |
(* No scope, we inherit the initial format *) |
| 230 |
|
| 231 |
Notation "x %% y" := (x*y) : bar_scope. (* Inherit the format *) |
| 232 |
Open Scope bar_scope. |
| 233 |
Check 3 %% 4. |
| 234 |
|
| 235 |
(* Different scope and no reserved notation, we don't warn *) |
| 236 |
|
| 237 |
Notation "x %% y" := (x*y) (at level 47, format "x %% y") : bar'_scope. |
| 238 |
Open Scope bar'_scope. |
| 239 |
Check 3 %% 4. |
| 240 |
|
| 241 |
(* Warn for combination of "only parsing" and "format" *) |
| 242 |
|
| 243 |
Notation "###" := 0 (at level 0, only parsing, format "###"). |
| 244 |
|
| 245 |
(* In reserved notation, warn only for the "only parsing" *) |
| 246 |
|
| 247 |
Reserved Notation "##" (at level 0, only parsing, format "##"). |
| 248 |
|
| 249 |
End N. |
| 250 |
|
| 251 |
Module O. |
| 252 |
|
| 253 |
Abbreviation U t := (match t with 0 => 0 | S t => t | _ => 0 end). |
| 254 |
Check fun x => U (S x). |
| 255 |
Abbreviation V t := (t,fun t => t). |
| 256 |
Check V tt. |
| 257 |
Check fun x : nat => V x. |
| 258 |
|
| 259 |
End O. |
| 260 |
|
| 261 |
Module Bug12691. |
| 262 |
|
| 263 |
Notation "x :=: y" := True (at level 70, no associativity, only parsing). |
| 264 |
Notation "x :=: y" := (x = y). |
| 265 |
Check (0 :=: 0). |
| 266 |
|
| 267 |
End Bug12691. |
| 268 |
|
| 269 |
Module CoercionEntryTransitivity. |
| 270 |
|
| 271 |
Declare Custom Entry com. |
| 272 |
Declare Custom Entry com_top. |
| 273 |
Notation "<{ e }>" := e (at level 0, e custom com_top at level 99). |
| 274 |
Notation "x ; y" := |
| 275 |
(x + y) |
| 276 |
(in custom com_top at level 90, x custom com at level 90, right associativity). |
| 277 |
Notation "x" := x (in custom com at level 0, x constr at level 0). |
| 278 |
Notation "x" := x (in custom com_top at level 90, x custom com at level 90). |
| 279 |
|
| 280 |
Check fun x => <{ x ; (S x) }>. |
| 281 |
|
| 282 |
End CoercionEntryTransitivity. |
| 283 |
|
| 284 |
Module CoercionEntryOnlyParsing. |
| 285 |
|
| 286 |
(* bug #15335 *) |
| 287 |
Declare Custom Entry ent. |
| 288 |
Notation "ent:( x )" := x (x custom ent, only parsing). |
| 289 |
Notation "!" := Set (in custom ent at level 0). |
| 290 |
Check ent:( ! ). |
| 291 |
|
| 292 |
End CoercionEntryOnlyParsing. |
| 293 |
|
| 294 |
Module CustomIdentOnlyParsing. |
| 295 |
|
| 296 |
Declare Custom Entry ent2. |
| 297 |
Notation "ent:( x )" := x (x custom ent2, format "ent:( x )"). |
| 298 |
Notation "# x" := (S x) (in custom ent2 at level 2, x at level 0). |
| 299 |
Notation "x" := x (in custom ent2 at level 0, x ident, only parsing). |
| 300 |
Check fun x : nat => ent:(# x). |
| 301 |
|
| 302 |
End CustomIdentOnlyParsing. |
| 303 |
|
| 304 |
Module CustomGlobalOnlyParsing. |
| 305 |
|
| 306 |
Declare Custom Entry ent3. |
| 307 |
Notation "ent:( x )" := x (x custom ent3, format "ent:( x )"). |
| 308 |
Notation "# x" := (S x) (in custom ent3 at level 2, x at level 0). |
| 309 |
Notation "x" := x (in custom ent3 at level 0, x global, only parsing). |
| 310 |
Check ent:(True). |
| 311 |
|
| 312 |
End CustomGlobalOnlyParsing. |
| 313 |
|
| 314 |
(* Some corner cases *) |
| 315 |
|
| 316 |
Module P. |
| 317 |
|
| 318 |
(* Basic rules: |
| 319 |
- a section variable be used for itself and as a binding variable |
| 320 |
- a global name cannot be used for itself and as a binding variable |
| 321 |
*) |
| 322 |
|
| 323 |
Definition pseudo_force {A} (n:A) (P:A -> Prop) := forall n', n' = n -> P n'. |
| 324 |
|
| 325 |
Module NotationMixedTermBinderAsIdent. |
| 326 |
|
| 327 |
Notation "▢_ n P" := (pseudo_force n (fun n => P)) |
| 328 |
(at level 2, n ident, P at level 9, format "▢_ n P"). |
| 329 |
Check exists p, ▢_p (p >= 1). |
| 330 |
Section S. |
| 331 |
Variable n:nat. |
| 332 |
Check ▢_n (n >= 1). |
| 333 |
End S. |
| 334 |
Fail Check ▢_nat (nat = bool). |
| 335 |
Fail Check ▢_O (O >= 1). |
| 336 |
Axiom n:nat. |
| 337 |
Fail Check ▢_n (n >= 1). |
| 338 |
|
| 339 |
End NotationMixedTermBinderAsIdent. |
| 340 |
|
| 341 |
Module NotationMixedTermBinderAsPattern. |
| 342 |
|
| 343 |
Notation "▢_ n P" := (pseudo_force n (fun n => P)) |
| 344 |
(at level 2, n pattern, P at level 9, format "▢_ n P"). |
| 345 |
Check exists x y, ▢_(x,y) (x >= 1 /\ y >= 2). |
| 346 |
Section S. |
| 347 |
Variable n:nat. |
| 348 |
Check ▢_n (n >= 1). |
| 349 |
End S. |
| 350 |
Fail Check ▢_nat (nat = bool). |
| 351 |
Check ▢_tt (tt = tt). |
| 352 |
Axiom n:nat. |
| 353 |
Fail Check ▢_n (n >= 1). |
| 354 |
|
| 355 |
End NotationMixedTermBinderAsPattern. |
| 356 |
|
| 357 |
Module NotationMixedTermBinderAsStrictPattern. |
| 358 |
|
| 359 |
Notation "▢_ n P" := (pseudo_force n (fun n => P)) |
| 360 |
(at level 2, n strict pattern, P at level 9, format "▢_ n P"). |
| 361 |
Check exists x y, ▢_(x,y) (x >= 1 /\ y >= 2). |
| 362 |
Section S. |
| 363 |
Variable n:nat. |
| 364 |
Check ▢_n (n >= 1). |
| 365 |
End S. |
| 366 |
Fail Check ▢_nat (nat = bool). |
| 367 |
Check ▢_tt (tt = tt). |
| 368 |
Axiom n:nat. |
| 369 |
Fail Check ▢_n (n >= 1). |
| 370 |
|
| 371 |
End NotationMixedTermBinderAsStrictPattern. |
| 372 |
|
| 373 |
Module AbbreviationMixedTermBinderAsStrictPattern. |
| 374 |
|
| 375 |
Abbreviation myforce n P := (pseudo_force n (fun n => P)). |
| 376 |
Check exists x y, myforce (x,y) (x >= 1 /\ y >= 2). |
| 377 |
Section S. |
| 378 |
Variable n:nat. |
| 379 |
Check myforce n (n >= 1). (* strict hence not used for printing *) |
| 380 |
End S. |
| 381 |
Fail Check myforce nat (nat = bool). |
| 382 |
Check myforce tt (tt = tt). |
| 383 |
Axiom n:nat. |
| 384 |
Fail Check myforce n (n >= 1). |
| 385 |
|
| 386 |
End AbbreviationMixedTermBinderAsStrictPattern. |
| 387 |
|
| 388 |
Module Bug4765Part. |
| 389 |
|
| 390 |
Abbreviation id x := ((fun y => y) x). |
| 391 |
Check id nat. |
| 392 |
|
| 393 |
Abbreviation id' x := ((fun x => x) x). |
| 394 |
Check fun a : bool => id' a. |
| 395 |
Check fun nat : bool => id' nat. |
| 396 |
Fail Check id' nat. |
| 397 |
|
| 398 |
End Bug4765Part. |
| 399 |
|
| 400 |
Module NotationBinderNotMixedWithTerms. |
| 401 |
|
| 402 |
Notation "!! x , P" := (forall x, P) (at level 200, x pattern). |
| 403 |
Check !! nat, nat = true. |
| 404 |
|
| 405 |
Notation "!!! x , P" := (forall x, P) (at level 200). |
| 406 |
Check !!! nat, nat = true. |
| 407 |
|
| 408 |
Notation "!!!! x , P" := (forall x, P) (at level 200, x strict pattern). |
| 409 |
Check !!!! (nat,id), nat = true /\ id = false. |
| 410 |
|
| 411 |
End NotationBinderNotMixedWithTerms. |
| 412 |
|
| 413 |
End P. |
| 414 |
|
| 415 |
Module MorePrecise1. |
| 416 |
|
| 417 |
(* A notation with limited iteration is strictly more precise than a |
| 418 |
notation with unlimited iteration *) |
| 419 |
|
| 420 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 421 |
(at level 200, x binder, y binder, right associativity, |
| 422 |
format "'[ ' '[ ' ∀ x .. y ']' , '/' P ']'") : type_scope. |
| 423 |
|
| 424 |
Check forall x, x = 0. |
| 425 |
|
| 426 |
Notation "∀₁ z , P" := (forall z, P) |
| 427 |
(at level 200, right associativity) : type_scope. |
| 428 |
|
| 429 |
Check forall x, x = 0. |
| 430 |
|
| 431 |
Notation "∀₂ y x , P" := (forall y x, P) |
| 432 |
(at level 200, right associativity) : type_scope. |
| 433 |
|
| 434 |
Check forall x, x = 0. |
| 435 |
Check forall x y, x + y = 0. |
| 436 |
|
| 437 |
Notation "(( x , y ))" := (x,y) : core_scope. |
| 438 |
|
| 439 |
Check ((1,2)). |
| 440 |
|
| 441 |
End MorePrecise1. |
| 442 |
|
| 443 |
Module MorePrecise2. |
| 444 |
|
| 445 |
(* Case of a bound binder *) |
| 446 |
Notation "%% [ x == y ]" := (forall x, S x = y) (at level 0, x pattern, y at level 60). |
| 447 |
|
| 448 |
(* Case of an internal binder *) |
| 449 |
Notation "%%% [ y ]" := (forall x : nat, x = y) (at level 0). |
| 450 |
|
| 451 |
(* Check that the two previous notations are indeed finer *) |
| 452 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 453 |
(at level 200, x binder, y binder, right associativity, |
| 454 |
format "'[ ' '[ ' ∀ x .. y ']' , '/' P ']'"). |
| 455 |
Notation "∀' x .. y , P" := (forall y, .. (forall x, P) ..) |
| 456 |
(at level 200, x binder, y binder, right associativity, |
| 457 |
format "'[ ' '[ ' ∀' x .. y ']' , '/' P ']'"). |
| 458 |
|
| 459 |
Check %% [x == 1]. |
| 460 |
Check %%% [1]. |
| 461 |
|
| 462 |
Notation "[[ x ]]" := (pair 1 x). |
| 463 |
|
| 464 |
Notation "( x ; y ; .. ; z )" := (pair .. (pair x y) .. z). |
| 465 |
Notation "[ x ; y ; .. ; z ]" := (pair .. (pair x z) .. y). |
| 466 |
|
| 467 |
(* Check which is finer *) |
| 468 |
Check [[ 2 ]]. |
| 469 |
|
| 470 |
End MorePrecise2. |
| 471 |
|
| 472 |
Module MorePrecise3. |
| 473 |
|
| 474 |
(* This is about a binder not bound in a notation being strictly more |
| 475 |
precise than a binder bound in the notation (since the notation |
| 476 |
applies - a priori - stricly less often) *) |
| 477 |
|
| 478 |
Notation "%%%" := (forall x, x) (at level 0). |
| 479 |
|
| 480 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 481 |
(at level 200, x binder, y binder, right associativity, |
| 482 |
format "'[ ' '[ ' ∀ x .. y ']' , '/' P ']'"). |
| 483 |
|
| 484 |
Check %%%. |
| 485 |
|
| 486 |
End MorePrecise3. |
| 487 |
|
| 488 |
Module TypedPattern. |
| 489 |
|
| 490 |
Notation "## x P" := (forall x:nat*nat, P) (x pattern, at level 1). |
| 491 |
Check ## (x,y) (x=0). |
| 492 |
Fail Check ## ((x,y):bool*bool) (x=y). |
| 493 |
|
| 494 |
End TypedPattern. |
| 495 |
|
| 496 |
Module SingleBinder. |
| 497 |
|
| 498 |
Notation "## x P" := (forall x, x = x -> P) (x binder, at level 1). |
| 499 |
Check ## '(x,y) (x+y=0). |
| 500 |
Check ## (x:nat) (x=0). |
| 501 |
Check ## '((x,y):nat*nat) (x=0). |
| 502 |
Check fun (f : ## {a} (a=0)) => f (a:=1) eq_refl. |
| 503 |
|
| 504 |
End SingleBinder. |
| 505 |
|
| 506 |
Module GenericFormatPrecedence. |
| 507 |
(* Check that if a generic format exists, we use it preferably to no |
| 508 |
explicit generic format *) |
| 509 |
Notation "[ 'MyNotation' G ]" := (S G) (at level 0, format "[ 'MyNotation' G ]") : nat_scope. |
| 510 |
Notation "[ 'MyNotation' G ]" := (G+0) (at level 0, only parsing) : bool_scope. |
| 511 |
Notation "[ 'MyNotation' G ]" := (G*0). |
| 512 |
Check 0*0. |
| 513 |
End GenericFormatPrecedence. |
| 514 |
|
| 515 |
Module LeadingIdent. |
| 516 |
|
| 517 |
Notation "'MyNone' +" := None (format "'MyNone' +"). |
| 518 |
Check fun MyNone : nat => MyNone. |
| 519 |
Check MyNone+. |
| 520 |
Check Some MyNone+. |
| 521 |
|
| 522 |
End LeadingIdent. |
| 523 |
|
| 524 |
Module SymbolsStartingWithNumbers. |
| 525 |
|
| 526 |
Notation "0+" := None. |
| 527 |
Check 0+. |
| 528 |
|
| 529 |
End SymbolsStartingWithNumbers. |
| 530 |
|
| 531 |
Module LeadingNumber. |
| 532 |
|
| 533 |
Notation "0 +" := None (format "0 +"). |
| 534 |
Check 0+. |
| 535 |
Check 0. |
| 536 |
|
| 537 |
End LeadingNumber. |
| 538 |
|
| 539 |
Module Incompatibility. |
| 540 |
|
| 541 |
Notation "'func' x .. y , P" := (fun x => .. (fun y => P) ..) (x binder, y binder, at level 200). |
| 542 |
Fail Notation "'func' x .. y , P" := (pair x .. (pair y P) ..) (at level 200). |
| 543 |
|
| 544 |
Declare Custom Entry foo. |
| 545 |
Declare Custom Entry bar. |
| 546 |
Notation "[[ x ]]" := x (x custom foo) : nat_scope. |
| 547 |
Fail Notation "[[ x ]]" := x (x custom bar) : type_scope. |
| 548 |
|
| 549 |
End Incompatibility. |
| 550 |
|
| 551 |
Module RecursivePatternsArgumentsInRecursiveNotations. |
| 552 |
|
| 553 |
Notation "'λ' x .. y , t" := (fun x => .. (fun y => t) ..) |
| 554 |
(at level 200, x binder, y binder, right associativity, |
| 555 |
format "'[ ' '[ ' 'λ' x .. y ']' , '/' t ']'"). |
| 556 |
|
| 557 |
Notation "'lambda' x .. y , t" := (λ x .. y, t) (at level 200, x binder, y binder). |
| 558 |
|
| 559 |
Check lambda x y, x+y=0. |
| 560 |
|
| 561 |
End RecursivePatternsArgumentsInRecursiveNotations. |
| 562 |
|
| 563 |
Module CyclicNotations. |
| 564 |
|
| 565 |
Notation "! x" := (list x) (at level 2, x at level 50, right associativity, format "! x"). |
| 566 |
Check ((!!nat) + bool)%type. |
| 567 |
|
| 568 |
End CyclicNotations. |
| 569 |
|
| 570 |
Module CustomCyclicNotations. |
| 571 |
|
| 572 |
Declare Custom Entry myconstr2. |
| 573 |
Notation "[ x ]" := x (x custom myconstr2 at level 6). |
| 574 |
Notation "! x" := (x,1) (in custom myconstr2 at level 1, x at level 2, format "! x"). |
| 575 |
Notation "x + y" := (x,y,2) (in custom myconstr2 at level 2, left associativity). |
| 576 |
Notation "x" := x (in custom myconstr2 at level 0, x ident). |
| 577 |
|
| 578 |
(* Check that the custom notation is not used, because parentheses are |
| 579 |
missing in the entry *) |
| 580 |
Check fun z:nat => ((z,1),z,2). |
| 581 |
|
| 582 |
Notation "( x )" := x (in custom myconstr2 at level 0, x at level 2). |
| 583 |
|
| 584 |
(* Check that parentheses are preserved when an entry refers on the |
| 585 |
right on a higher level than where it is *) |
| 586 |
Check fun z:nat => [(!! z) + z]. |
| 587 |
|
| 588 |
End CustomCyclicNotations. |
| 589 |
|
| 590 |
Module RecursivePatternsInMatch. |
| 591 |
|
| 592 |
Remove Printing Let prod. |
| 593 |
Unset Printing Matching. |
| 594 |
|
| 595 |
Notation "'uncurryλ' x1 .. xn => body" |
| 596 |
:= (fun x => match x with (pair x x1) => .. (match x with (pair x xn) => let 'tt := x in body end) .. end) |
| 597 |
(at level 200, x1 binder, xn binder, right associativity). |
| 598 |
|
| 599 |
Check uncurryλ a b c => a + b + c. |
| 600 |
|
| 601 |
(* Check other forms of binders, but too complex interaction |
| 602 |
with pattern-matching compaction for printing *) |
| 603 |
Check uncurryλ '(a,b) (d:=1) c => a + b + c + d. |
| 604 |
|
| 605 |
Set Printing Matching. |
| 606 |
Check uncurryλ '(a,b) (d:=1) c => a + b + c + d. |
| 607 |
|
| 608 |
(* This is a case where printing is easy though, relying on pattern-matching compaction *) |
| 609 |
Check uncurryλ '(a,b) => a + b. |
| 610 |
|
| 611 |
Notation "'lets' x1 .. xn := c 'in' body" |
| 612 |
:= (let x1 := c in .. (let xn := c in body) ..) |
| 613 |
(at level 200, x1 binder, xn binder, right associativity). |
| 614 |
|
| 615 |
Check lets a b c := 0 in a + b + c. |
| 616 |
|
| 617 |
(* Check other forms of binders, but too complex interaction |
| 618 |
with pattern-matching factorization for printing *) |
| 619 |
Check lets '(a,b) (d:=1) '(c,e) := (0,0) in a + b + c + d + e. |
| 620 |
|
| 621 |
End RecursivePatternsInMatch. |