Skip to content

Commit fa49a48

Browse files
committed
Add "of _ & _ & _" syntax
1 parent 3d4537b commit fa49a48

File tree

11 files changed

+28
-14
lines changed

11 files changed

+28
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- **Added:**
2+
new syntactic sugars `of T` and `& T` for anonymous binders
3+
`(_ : T)`. In particular, this enables the
4+
`Variant t := C1 of a & b & c | C2 of d.` syntax.
5+
This adds the new reserved keyword `of`
6+
(`#21478 <https://github.com/rocq-prover/rocq/pull/21478>`_,
7+
by Pierre Roux).

doc/sphinx/language/core/assumptions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Binders
2020
| @generalizing_binder
2121
| ( @name : @type %| @term )
2222
| ' @pattern0
23+
| {| of | & } @term99
2324
2425
Various constructions such as :g:`fun`, :g:`forall`, :g:`fix` and :g:`cofix`
2526
*bind* variables. A binding is represented by an identifier. If the binding
@@ -38,6 +39,8 @@ variable can be introduced at the same time. It is also possible to give
3839
the type of the variable as follows:
3940
:n:`(@ident : @type := @term)`.
4041

42+
`of T` and `& T` are syntactic sugar for anonymous binders `(_ : T)`.
43+
4144
`(x : T | P)` is syntactic sugar for `(x : @Stdlib.Init.Specif.sig _ (fun x : T => P))`,
4245
which would more typically be written `(x : {x : T | P})`.
4346
Since `(x : T | P)` uses `sig` directly,

doc/sphinx/language/core/basic.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Keywords
189189

190190
_ Axiom CoFixpoint Definition Fixpoint Hypothesis Parameter Prop
191191
SProp Set Theorem Type Variable as at cofix else end
192-
fix for forall fun if in let match return then where with
192+
fix for forall fun if in let match of return then where with
193193

194194
The following are keywords defined in notations or plugins loaded in the :term:`prelude`::
195195

doc/tools/docgram/fullGrammar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ closed_binder: [
348348
| "`{" LIST1 typeclass_constraint SEP "," "}"
349349
| "`[" LIST1 typeclass_constraint SEP "," "]"
350350
| "'" pattern0
351+
| [ "of" | "&" ] term99
351352
]
352353

353354
one_open_binder: [

doc/tools/docgram/orderedGrammar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ binder: [
405405
| generalizing_binder
406406
| "(" name ":" type "|" term ")"
407407
| "'" pattern0
408+
| [ "of" | "&" ] term99
408409
]
409410

410411
implicit_binders: [

parsing/g_constr.mlg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,9 @@ GRAMMAR EXTEND Gram
508508
{ List.map (fun (n, b, t) -> CLocalAssum ([n], None, Generalized (MaxImplicit, b), t)) tc }
509509
| "`["; tc = LIST1 typeclass_constraint SEP "," ; "]" ->
510510
{ List.map (fun (n, b, t) -> CLocalAssum ([n], None, Generalized (NonMaxImplicit, b), t)) tc }
511-
| "'"; p = pattern LEVEL "0" -> { [CLocalPattern p] } ] ]
511+
| "'"; p = pattern LEVEL "0" -> { [CLocalPattern p] }
512+
| ["of" -> { () } | "&" -> { () } ]; c = term LEVEL "99" ->
513+
{ [CLocalAssum ([CAst.make ~loc Anonymous], None, Default Explicit, c)] } ] ]
512514
;
513515
one_open_binder:
514516
[ [ na = name -> { (pat_of_name na, Explicit) }

plugins/ssr/ssrvernac.mlg

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ GRAMMAR EXTEND Gram
116116
] ];
117117
END
118118

119-
GRAMMAR EXTEND Gram
120-
GLOBAL: closed_binder;
121-
closed_binder: TOP [
122-
[ ["of" -> { () } | "&" -> { () } ]; c = term LEVEL "99" ->
123-
{ [CLocalAssum ([CAst.make ~loc Anonymous], None, Default Explicit, c)] }
124-
] ];
125-
END
126-
127119
(** Vernacular commands: Prenex Implicits *)
128120

129121
(* This should really be implemented as an extension to the implicit *)

test-suite/output/PrintKeywords.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ if
8383
in
8484
let
8585
match
86+
of
8687
return
8788
then
8889
using

theories/Corelib/Classes/CMorphisms.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Section GenericInstances.
437437
Proper R' (m x).
438438
Proof. simpl_crelation. Qed.
439439

440-
Class Params {A} (of : A) (arity : nat).
440+
Class Params {A} (from : A) (arity : nat).
441441

442442
Lemma flip_respectful {A B} (R : crelation A) (R' : crelation B) :
443443
relation_equivalence (flip (R ==> R')) (flip R ==> flip R').

theories/Corelib/Classes/Morphisms.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ Class PartialApplication.
538538

539539
CoInductive normalization_done : Prop := did_normalization.
540540

541-
Class Params {A : Type} (of : A) (arity : nat).
541+
Class Params {A : Type} (from : A) (arity : nat).
542542
#[global] Instance eq_pars : Params (@eq) 1 := {}.
543543
#[global] Instance iff_pars : Params (@iff) 0 := {}.
544544
#[global] Instance impl_pars : Params (@impl) 0 := {}.

0 commit comments

Comments
 (0)