| 1 |
(**********************************************************************) |
| 2 |
(* Check precedence, spacing, etc. in printing with curly brackets *) |
| 3 |
|
| 4 |
Check {x|x=0}+{True/\False}+{forall x, x=0}. |
| 5 |
|
| 6 |
(**********************************************************************) |
| 7 |
(* Check printing of notations with several instances of a recursive pattern *) |
| 8 |
(* Was wrong but I could not trigger a problem due to the collision between *) |
| 9 |
(* different instances of ".." *) |
| 10 |
|
| 11 |
Notation "[< x , y , .. , z >]" := (pair (.. (pair x y) ..) z,pair y ( .. (pair z x) ..)). |
| 12 |
Check [<0,2>]. |
| 13 |
Check ((0,2),(2,0)). |
| 14 |
Check ((0,2),(2,2)). |
| 15 |
Unset Printing Notations. |
| 16 |
Check [<0,2>]. |
| 17 |
Set Printing Notations. |
| 18 |
|
| 19 |
Notation "<< x , y , .. , z >>" := ((.. (x,y) .., z),(z, .. (y,x) ..)). |
| 20 |
Check <<0,2,4>>. |
| 21 |
Check (((0,2),4),(4,(2,0))). |
| 22 |
Check (((0,2),4),(2,(2,0))). |
| 23 |
Check (((0,2),4),(0,(2,4))). |
| 24 |
Unset Printing Notations. |
| 25 |
Check <<0,2,4>>. |
| 26 |
Set Printing Notations. |
| 27 |
|
| 28 |
(**********************************************************************) |
| 29 |
(* Check notations with recursive notations both in binders and terms *) |
| 30 |
|
| 31 |
Notation "'ETA' x .. y , f" := |
| 32 |
(fun x => .. (fun y => (.. (f x) ..) y ) ..) |
| 33 |
(at level 200, x binder, y binder). |
| 34 |
Check ETA (x:nat) (y:nat), Nat.add. |
| 35 |
Check ETA (x y:nat), Nat.add. |
| 36 |
Check ETA x y, Nat.add. |
| 37 |
Unset Printing Notations. |
| 38 |
Check ETA (x:nat) (y:nat), Nat.add. |
| 39 |
Set Printing Notations. |
| 40 |
Check ETA x y, le_S. |
| 41 |
|
| 42 |
Notation "'CURRY' x .. y , f" := (fun x => .. (fun y => f (x, .. (y,tt) ..)) ..) |
| 43 |
(at level 200, x binder, y binder). |
| 44 |
Check fun f => CURRY (x:nat) (y:bool), f. |
| 45 |
|
| 46 |
Notation "'CURRYINV' x .. y , f" := (fun x => .. (fun y => f (y, .. (x,tt) ..)) ..) |
| 47 |
(at level 200, x binder, y binder). |
| 48 |
Check fun f => CURRYINV (x:nat) (y:bool), f. |
| 49 |
|
| 50 |
Notation "'CURRYLEFT' x .. y , f" := (fun x => .. (fun y => f (.. (tt,x) .., y)) ..) |
| 51 |
(at level 200, x binder, y binder). |
| 52 |
Check fun f => CURRYLEFT (x:nat) (y:bool), f. |
| 53 |
|
| 54 |
Notation "'CURRYINVLEFT' x .. y , f" := (fun x => .. (fun y => f (.. (tt,y) .., x)) ..) |
| 55 |
(at level 200, x binder, y binder). |
| 56 |
Check fun f => CURRYINVLEFT (x:nat) (y:bool), f. |
| 57 |
|
| 58 |
(**********************************************************************) |
| 59 |
(* Notations with variables bound both as a term and as a binder *) |
| 60 |
(* This is #4592 *) |
| 61 |
|
| 62 |
Notation "{# x | P }" := (ex2 (fun y => x = y) (fun x => P)). |
| 63 |
Check forall n:nat, {# n | 1 > n}. |
| 64 |
|
| 65 |
Parameter foo : forall {T}(x : T)(P : T -> Prop), Prop. |
| 66 |
Notation "{| x | P |}" := (foo x (fun x => P)). |
| 67 |
Check forall x:nat, {| x | x > 0 |}. |
| 68 |
|
| 69 |
Check ex2 (fun x => x=1) (fun x0 => x0=2). |
| 70 |
|
| 71 |
(* Other tests about alpha-conversions: the following notation |
| 72 |
contains all three kinds of bindings: |
| 73 |
|
| 74 |
- x is bound in the lhs as a term and a binder: its name is forced |
| 75 |
by its position as a term; it can bind variables in P |
| 76 |
- y is bound in the lhs as a binder only: its name is given by its |
| 77 |
name as a binder in the term to display; it can bind variables in P |
| 78 |
- z is a binder local to the rhs; it cannot bind a variable in P |
| 79 |
*) |
| 80 |
|
| 81 |
Parameter foo2 : forall {T}(x : T)(P : T -> T -> T -> Prop), Prop. |
| 82 |
Notation "{| x , y | P |}_2" := (foo2 x (fun x y z => P z y x)). |
| 83 |
|
| 84 |
(* Not printable: z (resp c, n) occurs in P *) |
| 85 |
Check fun n => foo2 n (fun x y z => (fun _ _ _ => x+y+z=0) z y x). |
| 86 |
Check fun n => foo2 n (fun a b c => (fun _ _ _ => a+b+c=0) c b a). |
| 87 |
Check fun n => foo2 n (fun n y z => (fun _ _ _ => n+y+z=0) z y n). |
| 88 |
Check fun n => foo2 n (fun x n z => (fun _ _ _ => x+n+z=0) z n x). |
| 89 |
Check fun n => foo2 n (fun x y n => (fun _ _ _ => x+y+n=0) n y x). |
| 90 |
|
| 91 |
(* Printable *) |
| 92 |
Check fun n => foo2 n (fun x y z => (fun _ _ _ => x+y=0) z y x). |
| 93 |
Check fun n => foo2 n (fun n y z => (fun _ _ _ => n+y=0) z y n). |
| 94 |
Check fun n => foo2 n (fun x n z => (fun _ _ _ => x+n=0) z n x). |
| 95 |
|
| 96 |
(* Not printable: renaming x into n would bind the 2nd occurrence of n *) |
| 97 |
Check fun n => foo2 n (fun x y z => (fun _ _ _ => x+y+n=0) z y x). |
| 98 |
Check fun n => foo2 n (fun x y z => (fun _ _ _ => x+y+n=0) z y x). |
| 99 |
|
| 100 |
(* Other tests *) |
| 101 |
Parameter foo3 : forall {T}(x : T)(P : T -> T -> T -> Prop), Prop. |
| 102 |
Notation "{| x , P |}_3" := (foo3 x (fun x x x => P x)). |
| 103 |
|
| 104 |
(* Printable *) |
| 105 |
Check fun n : nat => foo3 n (fun x y z => (fun _ => 0=0) z). |
| 106 |
Check fun n => foo3 n (fun x y z => (fun _ => z=0) z). |
| 107 |
|
| 108 |
(* Not printable: renaming z in n would hide the renaming of x into n *) |
| 109 |
Check fun n => foo3 n (fun x y z => (fun _ => x=0) z). |
| 110 |
|
| 111 |
(* Other tests *) |
| 112 |
Parameter foo4 : forall {T}(x : T)(P : T -> T -> T -> Prop), Prop. |
| 113 |
Notation "{| x , P |}_4" := (foo4 x (fun x _ z => P z)). |
| 114 |
|
| 115 |
(* Printable *) |
| 116 |
Check fun n : nat => foo4 n (fun x y z => (fun _ => 0=0) z). |
| 117 |
Check fun n => foo4 n (fun x y z => (fun _ => x=0) z). |
| 118 |
|
| 119 |
(* Not printable: y, z not allowed to occur in P *) |
| 120 |
Check fun n => foo4 n (fun x y z => (fun _ => z=0) z). |
| 121 |
Check fun n => foo4 n (fun x y z => (fun _ => y=0) z). |
| 122 |
|
| 123 |
(**********************************************************************) |
| 124 |
(* Test printing of #4932 *) |
| 125 |
|
| 126 |
Inductive ftele : Type := |
| 127 |
| fb {T:Type} : T -> ftele |
| 128 |
| fr {T} : (T -> ftele) -> ftele. |
| 129 |
|
| 130 |
Fixpoint args ftele : Type := |
| 131 |
match ftele with |
| 132 |
| fb _ => unit |
| 133 |
| fr f => sigT (fun t => args (f t)) |
| 134 |
end. |
| 135 |
|
| 136 |
Definition fpack := sigT args. |
| 137 |
Definition pack fp fa : fpack := existT _ fp fa. |
| 138 |
|
| 139 |
Notation "'tele' x .. z := b" := |
| 140 |
(fun x => .. (fun z => |
| 141 |
pack (fr (fun x => .. ( fr (fun z => fb b) ) .. ) ) |
| 142 |
(existT _ x .. (existT _ z tt) .. ) |
| 143 |
) ..) |
| 144 |
(at level 85, x binder, z binder). |
| 145 |
|
| 146 |
Check tele (t:Type) '((y,z):nat*nat) (x:t) := tt. |
| 147 |
Check tele (t:Type) (y:=nat) (x:t) (z:y) := (y,z). |
| 148 |
|
| 149 |
(* Checking that "fun" in a notation does not mixed up with the |
| 150 |
detection of a recursive binder *) |
| 151 |
|
| 152 |
Notation "[ x ;; .. ;; y ]" := ((x,((fun u => S u), .. (y,(fun u => S u,fun v:nat => v)) ..))). |
| 153 |
Check [ fun x => x+0 ;; fun x => x+1 ;; fun x => x+2 ]. |
| 154 |
|
| 155 |
(* Cyprien's part of bug #4765 *) |
| 156 |
|
| 157 |
Section Bug4765. |
| 158 |
|
| 159 |
Abbreviation foo5 x T y := (fun x : T => y). |
| 160 |
Check foo5 x nat x. |
| 161 |
|
| 162 |
End Bug4765. |
| 163 |
|
| 164 |
(**********************************************************************) |
| 165 |
(* Test printing of #5526 *) |
| 166 |
|
| 167 |
Notation "x === x" := (eq_refl x) (only printing, at level 10). |
| 168 |
Check (fun x => eq_refl x). |
| 169 |
|
| 170 |
(* Test recursive notations with the recursive pattern repeated on the right *) |
| 171 |
|
| 172 |
Notation "{{ x , .. , y , z }}" := (pair x .. (pair y z) ..). |
| 173 |
Check {{0,1}}. |
| 174 |
Check {{0,1,2}}. |
| 175 |
Check {{0,1,2,3}}. |
| 176 |
|
| 177 |
(* Test printing of #5608 *) |
| 178 |
|
| 179 |
Reserved Notation "'letpair' x [1] = { A } ; 'return' ( b0 , b1 , .. , b2 )" |
| 180 |
(at level 200, format "'letpair' x [1] = { A } ; '//' 'return' ( b0 , b1 , .. , b2 )"). |
| 181 |
Notation "'letpair' x [1] = { a } ; 'return' ( b0 , b1 , .. , b2 )" := |
| 182 |
(let x:=a in ( .. (b0,b1) .., b2)). |
| 183 |
Check letpair x [1] = {0}; return (1,2,3,4). |
| 184 |
|
| 185 |
(* Allow level for leftmost nonterminal when printing-only, BZ#5739 *) |
| 186 |
|
| 187 |
Notation "* x" := (id x) (only printing, at level 15, format "* x"). |
| 188 |
Notation "x . y" := (x + y) (only printing, at level 20, x at level 14, left associativity, format "x . y"). |
| 189 |
Check (((id 1) + 2) + 3). |
| 190 |
Check (id (1 + 2)). |
| 191 |
|
| 192 |
(* Test spacing in #5569 *) |
| 193 |
|
| 194 |
Notation "{ { xL | xR // xcut } }" := (xL+xR+xcut) |
| 195 |
(at level 0, xR at level 39, format "{ { xL | xR // xcut } }"). |
| 196 |
Check 1+1+1. |
| 197 |
|
| 198 |
(* Test presence of notation variables in the recursive parts (introduced in dfdaf4de) *) |
| 199 |
Notation "!!! x .. y , b" := ((fun x => b), .. ((fun y => b), True) ..) (at level 200, x binder). |
| 200 |
Check !!! (x y:nat), True. |
| 201 |
|
| 202 |
(* Test contraction of "forall x, let 'pat := x in ..." into "forall 'pat, ..." *) |
| 203 |
(* for isolated "forall" (was not working already in 8.6) *) |
| 204 |
Notation "! x .. y , A" := (id (forall x, .. (id (forall y, A)) .. )) (at level 200, x binder). |
| 205 |
Check ! '(x,y), x+y=0. |
| 206 |
|
| 207 |
(* Check that the terminator of a recursive pattern is interpreted in |
| 208 |
the correct environment of bindings *) |
| 209 |
Notation "'exists_mixed' x .. y , P" := (ex (fun x => forall z:nat, .. (ex (fun y => forall z:nat, z=0 /\ P)) ..)) (at level 200, x binder). |
| 210 |
Check exists_mixed x y '(u,t), x+y=0/\u+t=0. |
| 211 |
Check exists_mixed x y '(z,t), x+y=0/\z+t=0. |
| 212 |
|
| 213 |
(* Check that intermediary let-in are inserted in between instances of |
| 214 |
the repeated pattern *) |
| 215 |
Notation "'exists_true' x .. y , P" := (exists x, True /\ .. (exists y, True /\ P) ..) (at level 200, x binder). |
| 216 |
Check exists_true '(x,y) (u:=0) '(z,t), x+y=0/\z+t=0. |
| 217 |
|
| 218 |
(* Check that generalized binders are correctly interpreted *) |
| 219 |
|
| 220 |
Module G. |
| 221 |
Generalizable Variables A R. |
| 222 |
Class Reflexive {A:Type} (R : A->A->Prop) := reflexivity : forall x : A, R x x. |
| 223 |
Check exists_true `(Reflexive A R), forall x, R x x. |
| 224 |
Check exists_true x `(Reflexive A R) y, x+y=0 -> forall z, R z z. |
| 225 |
End G. |
| 226 |
|
| 227 |
(* Allows recursive patterns for binders to be associative on the left *) |
| 228 |
Notation "!! x .. y # A #" := (.. (A,(forall x, True)) ..,(forall y, True)) (at level 0, x binder). |
| 229 |
Check !! a b : nat # True #. |
| 230 |
|
| 231 |
(* Examples where the recursive pattern refer several times to the recursive variable *) |
| 232 |
|
| 233 |
Notation "{{D x , .. , y }}" := ((x,x), .. ((y,y),(0,0)) ..). |
| 234 |
Check {{D 1, 2 }}. |
| 235 |
|
| 236 |
#[warning="-closed-notation-not-level-0"] |
| 237 |
Notation "! x .. y # A #" := |
| 238 |
((forall x, x=x), .. ((forall y, y=y), A) ..) |
| 239 |
(at level 200, x binder). |
| 240 |
Check ! a b : nat # True #. |
| 241 |
Check ((forall x, x=0), nat). (* should not use the notation *) |
| 242 |
|
| 243 |
Notation "!!!! x .. y # A #" := |
| 244 |
(((forall x, x=x),(forall x, x=0)), .. (((forall y, y=y),(forall y, y=0)), A) ..) |
| 245 |
(at level 0, x binder). |
| 246 |
Check !!!! a b : nat # True #. |
| 247 |
|
| 248 |
Notation "@@ x .. y # A # B #" := |
| 249 |
((forall x, .. (forall y, A) ..), (forall x, .. (forall y, B) ..)) |
| 250 |
(at level 0, x binder). |
| 251 |
Check @@ a b : nat # a=b # b=a #. |
| 252 |
|
| 253 |
Notation "'exists_non_null' x .. y , P" := |
| 254 |
(ex (fun x => x <> 0 /\ .. (ex (fun y => y <> 0 /\ P)) ..)) |
| 255 |
(at level 200, x binder). |
| 256 |
Check exists_non_null x y z t , x=y/\z=t. |
| 257 |
|
| 258 |
Notation "'forall_non_null' x .. y , P" := |
| 259 |
(forall x, x <> 0 -> .. (forall y, y <> 0 -> P) ..) |
| 260 |
(at level 200, x binder). |
| 261 |
Check forall_non_null x y z t , x=y/\z=t. |
| 262 |
|
| 263 |
(* Examples where the recursive pattern is in reverse order *) |
| 264 |
|
| 265 |
Notation "{{RL c , .. , d }}" := (pair d .. (pair c 0) ..). |
| 266 |
Check {{RL 1 , 2}}. |
| 267 |
|
| 268 |
Notation "{{RR c , .. , d }}" := (pair .. (pair 0 d) .. c). |
| 269 |
Check {{RR 1 , 2}}. |
| 270 |
|
| 271 |
Set Printing All. |
| 272 |
Check {{RL 1 , 2}}. |
| 273 |
Check {{RR 1 , 2}}. |
| 274 |
Unset Printing All. |
| 275 |
|
| 276 |
Notation "{{RLRR c , .. , d }}" := (pair d .. (pair c 0) .., pair .. (pair 0 d) .. c, pair c .. (pair d 0) .., pair .. (pair 0 c) .. d). |
| 277 |
Check {{RLRR 1 , 2}}. |
| 278 |
Unset Printing Notations. |
| 279 |
Check {{RLRR 1 , 2}}. |
| 280 |
Set Printing Notations. |
| 281 |
|
| 282 |
(* Check insensitivity of "match" clauses to order *) |
| 283 |
|
| 284 |
Module IfPat. |
| 285 |
Notation "'if' t 'is' n .+ 1 'then' p 'else' q" := |
| 286 |
(match t with S n => p | 0 => q end) |
| 287 |
(at level 200). |
| 288 |
Check fun x => if x is n.+1 then n else 1. |
| 289 |
End IfPat. |
| 290 |
|
| 291 |
(* Examples with binding patterns *) |
| 292 |
|
| 293 |
Check {'(x,y)|x+y=0}. |
| 294 |
|
| 295 |
Module D. |
| 296 |
Notation "'exists2'' x , p & q" := (ex2 (fun x => p) (fun x => q)) |
| 297 |
(at level 200, x pattern, p at level 200, right associativity, |
| 298 |
format "'[' 'exists2'' '/ ' x , '/ ' '[' p & '/' q ']' ']'") |
| 299 |
: type_scope. |
| 300 |
|
| 301 |
Check exists2' (x,y), x=0 & y=0. |
| 302 |
End D. |
| 303 |
|
| 304 |
(* Ensuring for reparsability that printer of notations does not use a |
| 305 |
pattern where only an ident could be reparsed *) |
| 306 |
|
| 307 |
Module E. |
| 308 |
Inductive myex2 {A:Type} (P Q:A -> Prop) : Prop := |
| 309 |
myex_intro2 : forall x:A, P x -> Q x -> myex2 P Q. |
| 310 |
Notation "'myexists2' x : A , p & q" := (myex2 (A:=A) (fun x => p) (fun x => q)) |
| 311 |
(at level 200, x name, A at level 200, p at level 200, right associativity, |
| 312 |
format "'[' 'myexists2' '/ ' x : A , '/ ' '[' p & '/' q ']' ']'") |
| 313 |
: type_scope. |
| 314 |
Check myex2 (fun x => let '(y,z) := x in y>z) (fun x => let '(y,z) := x in z>y). |
| 315 |
End E. |
| 316 |
|
| 317 |
(* A canonical example of a notation with a non-recursive binder *) |
| 318 |
|
| 319 |
Parameter myex : forall {A}, (A -> Prop) -> Prop. |
| 320 |
Notation "'myexists' x , p" := (myex (fun x => p)) |
| 321 |
(at level 200, x pattern, p at level 200, right associativity). |
| 322 |
|
| 323 |
(* A canonical example of a notation with recursive binders *) |
| 324 |
|
| 325 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 326 |
(at level 200, x binder, y binder, right associativity) : type_scope. |
| 327 |
|
| 328 |
(* Check that printing 'pat uses an "as" when the variable bound to |
| 329 |
the pattern is dependent. We check it for the three kinds of |
| 330 |
notations involving bindings of patterns *) |
| 331 |
|
| 332 |
Check fun '((x,y) as z) => x+y=0/\z=z. (* Primitive fun/forall *) |
| 333 |
Check myexists ((x,y) as z), x+y=0/\z=z. (* Isolated binding pattern *) |
| 334 |
Check exists '((x,y) as z), x+y=0/\z=z. (* Applicative recursive binder *) |
| 335 |
Check ∀ '((x,y) as z), x+y=0/\z=z. (* Other example of recursive binder, now treated as the exists case *) |
| 336 |
|
| 337 |
(* Check parsability and printability of irrefutable disjunctive patterns *) |
| 338 |
|
| 339 |
Check fun '(((x,y),true)|((x,y),false)) => x+y. |
| 340 |
Check myexists (((x,y),true)|((x,y),false)), x>y. |
| 341 |
Check exists '(((x,y),true)|((x,y),false)), x>y. |
| 342 |
Check ∀ '(((x,y),true)|((x,y),false)), x>y. |
| 343 |
|
| 344 |
(* Check Georges' printability of a "if is then else" notation *) |
| 345 |
|
| 346 |
Module IfPat2. |
| 347 |
Notation "'if' c 'is' p 'then' u 'else' v" := |
| 348 |
(match c with p => u | _ => v end) |
| 349 |
(at level 200, p pattern at level 100). |
| 350 |
Check fun p => if p is S n then n else 0. |
| 351 |
Check fun p => if p is Lt then 1 else 0. |
| 352 |
End IfPat2. |
| 353 |
|
| 354 |
(* Check that mixed binders and terms defaults to ident and not pattern *) |
| 355 |
Module F. |
| 356 |
(* First without an indirection *) |
| 357 |
Notation "[ n | t ]" := (n, (fun n : nat => t)). |
| 358 |
Check fun S : nat => [ S | S+S ]. |
| 359 |
Check fun N : nat => (N, (fun n => n+0)). (* another test in passing *) |
| 360 |
(* Then with an indirection *) |
| 361 |
Notation "[[ n | p | t ]]" := (n, (fun p : nat => t)). |
| 362 |
Notation "[[ n | t ]]" := [[ n | n | t ]]. |
| 363 |
Check fun S : nat => [[ S | S+S ]]. |
| 364 |
End F. |
| 365 |
|
| 366 |
(* Check parsability/printability of {x|P} and variants *) |
| 367 |
|
| 368 |
Check {I:nat|I=I}. |
| 369 |
Check {'I:True|I=I}. |
| 370 |
Check {'(x,y)|x+y=0}. |
| 371 |
|
| 372 |
(* Check exists2 with a pattern *) |
| 373 |
Check ex2 (fun x => let '(y,z) := x in y>z) (fun x => let '(y,z) := x in z>y). |
| 374 |
|
| 375 |
Module Issue7110. |
| 376 |
Open Scope list_scope. |
| 377 |
Notation "[ :: x1 , x2 , .. , xn & s ]" := (x1 :: x2 :: .. (xn :: s) ..) |
| 378 |
(at level 0). |
| 379 |
Definition foo (l : list nat) := |
| 380 |
match l with |
| 381 |
| a :: (b :: l) as l1 => l1 |
| 382 |
| _ => l |
| 383 |
end. |
| 384 |
Print foo. |
| 385 |
End Issue7110. |
| 386 |
|
| 387 |
Module LocateNotations. |
| 388 |
Locate "exists". |
| 389 |
Locate "( _ , _ , .. , _ )". |
| 390 |
End LocateNotations. |
| 391 |
|
| 392 |
Module Issue7731. |
| 393 |
|
| 394 |
Axiom (P : nat -> Prop). |
| 395 |
Parameter (X : nat). |
| 396 |
Notation "## @ E ^^^" := (P E) (at level 0, E at level 1, format "'[ ' ## '/' @ E '/' ^^^ ']'"). |
| 397 |
Notation "%" := X. |
| 398 |
|
| 399 |
Set Printing Width 7. |
| 400 |
Goal ## @ % ^^^. |
| 401 |
Show. |
| 402 |
Abort. |
| 403 |
|
| 404 |
End Issue7731. |
| 405 |
|
| 406 |
Module Issue8126. |
| 407 |
|
| 408 |
Definition myfoo (x : nat) (y : nat) (z : unit) := y. |
| 409 |
Abbreviation myfoo0 := (@myfoo 0). |
| 410 |
Abbreviation myfoo01 := (@myfoo0 1). |
| 411 |
Check myfoo 0 1 tt. (* was printing [myfoo0 1 HI], but should print [myfoo01 HI] *) |
| 412 |
Check myfoo0 1 tt. (* was printing [myfoo0 1 HI], but should print [myfoo01 HI] *) |
| 413 |
Check myfoo01 tt. (* was printing [myfoo0 1 HI], but should print [myfoo01 HI] *) |
| 414 |
|
| 415 |
End Issue8126. |
| 416 |
|
| 417 |
Module RecursiveNotationPartialApp. |
| 418 |
|
| 419 |
(* Discussed on Coq Club, 28 July 2020 *) |
| 420 |
Notation "x ⪯ y ⪯ .. ⪯ z ⪯ t" := |
| 421 |
((fun b A a => a <= b /\ A b) y .. ((fun b A a => a <= b /\ A b) z (fun b => b <= t)) .. x) |
| 422 |
(at level 70, y at next level, z at next level, t at next level). |
| 423 |
Check 1 ⪯ 2 ⪯ 3 ⪯ 4. |
| 424 |
|
| 425 |
End RecursiveNotationPartialApp. |
| 426 |
|
| 427 |
Module GoalConclBox. |
| 428 |
|
| 429 |
(* The conclusion was sometimes printed vertically (see |
| 430 |
https://coq.zulipchat.com/#narrow/stream/237977-Coq-users/topic/Strange.20newline.20in.20printing) |
| 431 |
*) |
| 432 |
|
| 433 |
Notation "|-_0 x" := (x = 0) (at level 70, format "|-_0 '/' x"). |
| 434 |
Lemma test x : |-_0 x. |
| 435 |
Show. |
| 436 |
Abort. |
| 437 |
|
| 438 |
Lemma test xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : |-_0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx * xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. |
| 439 |
Show. |
| 440 |
Abort. |
| 441 |
|
| 442 |
End GoalConclBox. |
| 443 |
|
| 444 |
Module PartOfIssue17094. |
| 445 |
|
| 446 |
Notation "'FORALL' x .. y , P" := (forall x , .. (forall y , P) .. ) |
| 447 |
(at level 200, x constr at level 8 as pattern, right associativity, |
| 448 |
format "'[ ' '[ ' 'FORALL' x .. y ']' , '/' P ']'") : type_scope. |
| 449 |
Notation "[[ x , y ]]" := (x, y). |
| 450 |
Check FORALL [[a , b]], a - b = 0. |
| 451 |
|
| 452 |
End PartOfIssue17094. |
| 453 |
|
| 454 |
Module PartOfIssue17094PrintingAssumption. |
| 455 |
|
| 456 |
Declare Custom Entry quoted. |
| 457 |
Notation "( x )" := x (in custom quoted at level 0, x at level 200). |
| 458 |
Notation "x" := x (in custom quoted at level 0, x global). |
| 459 |
Notation "{ A }" := A (in custom quoted at level 0, A constr at level 200). |
| 460 |
|
| 461 |
Axiom TypTerm : Type. |
| 462 |
Axiom qType : Type -> TypTerm. |
| 463 |
Axiom ValTerm : TypTerm -> Type. |
| 464 |
Notation "◻ A" := (ValTerm A) (at level 9, right associativity, A custom quoted at level 9). |
| 465 |
Notation "◻ A" := (qType (ValTerm A)) |
| 466 |
(in custom quoted at level 9, right associativity, A custom quoted at level 9). |
| 467 |
|
| 468 |
Declare Custom Entry quoted_binder. |
| 469 |
Notation "{ x }" := x (in custom quoted_binder at level 0, x constr). |
| 470 |
|
| 471 |
Axiom FORALL : forall {A : TypTerm} (B : ValTerm A -> TypTerm), TypTerm. |
| 472 |
Notation "∀' x .. y , P" := (FORALL (fun x => .. (FORALL (fun y => P)) .. )) |
| 473 |
(in custom quoted at level 200, x custom quoted_binder as pattern, right associativity, |
| 474 |
format "'[ ' '[ ' ∀' x .. y ']' , '/' P ']'") : type_scope. |
| 475 |
Check ∀ A (B : ValTerm A -> TypTerm), (∀ (a : ◻A), ◻{B a}) -> ◻(∀' {a}, {B a}). |
| 476 |
|
| 477 |
End PartOfIssue17094PrintingAssumption. |
| 478 |
|
| 479 |
Module PartOfIssue17094Pattern. |
| 480 |
|
| 481 |
(* The same but referring this time to a pattern *) |
| 482 |
|
| 483 |
Notation "'FORALL' x .. y , P" := (forall x , .. (forall y , P) .. ) |
| 484 |
(at level 200, x constr at level 8 as pattern, right associativity, |
| 485 |
format "'[ ' '[ ' 'FORALL' x .. y ']' , '/' P ']'") : type_scope. |
| 486 |
Notation "[[ x , y ]]" := (x,y) (x pattern, y pattern). |
| 487 |
Check FORALL [[a , b]], a - b = 0. |
| 488 |
|
| 489 |
End PartOfIssue17094Pattern. |
| 490 |
|
| 491 |
Module PartOfIssue17094Ident. |
| 492 |
|
| 493 |
(* A variant with custom entries and referring this time to a ident *) |
| 494 |
|
| 495 |
Declare Custom Entry quoted_binder'. |
| 496 |
Notation "x" := x (in custom quoted_binder' at level 0, x ident). |
| 497 |
Notation "'FORALL' x .. y , P" := (forall x , .. (forall y , P) .. ) |
| 498 |
(at level 200, x custom quoted_binder' as pattern, right associativity, |
| 499 |
format "'[ ' '[ ' 'FORALL' x .. y ']' , '/' P ']'") : type_scope. |
| 500 |
|
| 501 |
(* Note: notation not used for printing because no rule to print "a:nat" and "b:nat" *) |
| 502 |
Check FORALL a b, a - b = 0. |
| 503 |
|
| 504 |
End PartOfIssue17094Ident. |
| 505 |
|
| 506 |
Module BetterFix13078. |
| 507 |
|
| 508 |
(* We now support referring to ident and pattern in notations for pattern *) |
| 509 |
Notation "# x &" := (Some x) (at level 0, x pattern). |
| 510 |
Check fun (x : option unit) => match x with | None => None | # tt & => # tt & end. |
| 511 |
|
| 512 |
End BetterFix13078. |