Skip to content

Commit da652b2

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

File tree

14 files changed

+73
-45
lines changed

14 files changed

+73
-45
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
(`#21478 <https://github.com/rocq-prover/rocq/pull/21478>`_,
6+
by Pierre Roux).

doc/sphinx/addendum/generalized-rewriting.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ These commands support the :attr:`local` and :attr:`global` locality attributes.
176176
The default is :attr:`local` if the command is used inside a section, :attr:`global` otherwise.
177177
They also support the :attr:`universes(polymorphic)` attributes.
178178

179-
.. cmd:: Add Parametric Relation {* @binder } : @one_term__A @one_term__Aeq {? reflexivity proved by @one_term } {? symmetry proved by @one_term } {? transitivity proved by @one_term } as @ident
179+
.. cmd:: Add Parametric Relation @binders : @one_term__A @one_term__Aeq {? reflexivity proved by @one_term } {? symmetry proved by @one_term } {? transitivity proved by @one_term } as @ident
180180

181181
Declares a parametric relation of :n:`@one_term__A`, which is a `Type`, say `T`, with
182182
:n:`@one_term__Aeq`, which is a relation on `T`, i.e. of type `(T -> T -> Prop)`.
@@ -235,7 +235,7 @@ replace terms with related ones only in contexts that are syntactic
235235
compositions of parametric morphism instances declared with the
236236
following command.
237237

238-
.. cmd:: Add Parametric Morphism {* @binder } : @one_term with signature @term as @ident
238+
.. cmd:: Add Parametric Morphism @binders : @one_term with signature @term as @ident
239239

240240
Declares a parametric morphism :n:`@one_term` of
241241
signature :n:`@term`. The final identifier :token:`ident` gives a unique
@@ -777,7 +777,7 @@ Deprecated syntax and backward incompatibilities
777777
Notice that the syntax is not completely backward compatible since the
778778
identifier was not required.
779779

780-
.. cmd:: Add Parametric Setoid {* @binder } : @one_term @one_term @one_term as @ident
780+
.. cmd:: Add Parametric Setoid @binders : @one_term @one_term @one_term as @ident
781781
:undocumented:
782782

783783
.. cmd:: Add Morphism @one_term : @ident

doc/sphinx/addendum/type-classes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Command summary
289289
---------------
290290

291291
.. cmd:: Class @record_definition
292-
Class @ident_decl {* @binder } {? : @sort } := @constructor
292+
Class @ident_decl @binders {? : @sort } := @constructor
293293

294294
The first form declares a record and makes the record a typeclass with parameters
295295
:n:`{* @binder }` and the listed record fields.
@@ -344,7 +344,7 @@ Command summary
344344
or :n:`@constructor` with a right-hand-side that
345345
is not itself a Class has no effect (apart from emitting this warning).
346346

347-
.. cmd:: Instance {? @ident_decl {* @binder } } : @type {? @hint_info } {? {| := %{ {* @field_val } %} | := @term } }
347+
.. cmd:: Instance {? @ident_decl @binders } : @type {? @hint_info } {? {| := %{ {* @field_val } %} | := @term } }
348348

349349
Declares a typeclass instance named :token:`ident_decl` of the typeclass
350350
:n:`@type` with the specified parameters and with
@@ -380,7 +380,7 @@ Command summary
380380
to fill them. It works exactly as if no :term:`body` had been given and
381381
the :tacn:`refine` tactic has been used first.
382382

383-
.. cmd:: Declare Instance @ident_decl {* @binder } : @term {? @hint_info }
383+
.. cmd:: Declare Instance @ident_decl @binders : @term {? @hint_info }
384384

385385
In a :cmd:`Module Type`, declares that a corresponding concrete
386386
instance should exist in any implementation of this :cmd:`Module Type`. This

doc/sphinx/language/core/assumptions.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Binders
1111
.. prodn::
1212
open_binders ::= {+ @name } : @type
1313
| {+ @binder }
14+
| @anon_binders
15+
binders ::= {* @binder }
16+
| {* @binder } @anon_binders
17+
anon_binders ::= {| of | & } {+& @term99 }
1418
name ::= _
1519
| @ident
1620
binder ::= @name
@@ -38,6 +42,8 @@ variable can be introduced at the same time. It is also possible to give
3842
the type of the variable as follows:
3943
:n:`(@ident : @type := @term)`.
4044

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

doc/sphinx/language/core/coinductive.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Co-recursive functions: cofix
136136
.. prodn::
137137
term_cofix ::= let cofix @cofix_body in @term
138138
| cofix @cofix_body {? {+ with @cofix_body } for @ident }
139-
cofix_body ::= @ident {* @binder } {? : @type } := @term
139+
cofix_body ::= @ident @binders {? : @type } := @term
140140

141141
The expression
142142
":n:`cofix @ident__1 @binder__1 : @type__1 with … with @ident__n @binder__n : @type__n for @ident__i`"
@@ -154,7 +154,7 @@ Top-level definitions of corecursive functions
154154
.. insertprodn cofix_definition cofix_definition
155155
156156
.. prodn::
157-
cofix_definition ::= @ident_decl {* @binder } {? : @type } {? := @term } {? @decl_notations }
157+
cofix_definition ::= @ident_decl @binders {? : @type } {? := @term } {? @decl_notations }
158158

159159
This command introduces a method for constructing an infinite object of a
160160
coinductive type. For example, the stream containing all natural numbers can

doc/sphinx/language/core/definitions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Assertions cause Rocq to enter :term:`proof mode` (see :ref:`proofhandling`).
140140
Common tactics are described in the :ref:`tactics` chapter.
141141
The basic assertion command is:
142142

143-
.. cmd:: @thm_token @ident_decl {* @binder } : @type {* with @ident_decl {* @binder } : @type }
143+
.. cmd:: @thm_token @ident_decl @binders : @type {* with @ident_decl @binders : @type }
144144
:name: Theorem; Lemma; Fact; Remark; Corollary; Proposition; Property
145145

146146
.. insertprodn thm_token thm_token

doc/sphinx/language/core/inductive.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Inductive types
3131
.. insertprodn inductive_definition constructor
3232
3333
.. prodn::
34-
inductive_definition ::= @ident {? @cumul_univ_decl } {* @binder } {? %| {* @binder } } {? : @type } := {? {? %| } {+| @constructor } } {? @decl_notations }
35-
constructor ::= {* #[ {+, @attribute } ] } @ident {* @binder } {? @of_type_inst }
34+
inductive_definition ::= @ident {? @cumul_univ_decl } @binders {? %| @binders } {? : @type } := {? {? %| } {+| @constructor } } {? @decl_notations }
35+
constructor ::= {* #[ {+, @attribute } ] } @ident @binders {? @of_type_inst }
3636

3737
Defines one or more
3838
inductive types and its constructors. Rocq generates

doc/sphinx/language/core/records.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Defining record types
2121
.. insertprodn record_definition of_type_inst
2222
2323
.. prodn::
24-
record_definition ::= {? > } @ident_decl {* @binder } {? : @sort } {? := {? @ident } %{ {? {+; @record_field } {? ; } } %} {? as @ident } }
24+
record_definition ::= {? > } @ident_decl @binders {? : @sort } {? := {? @ident } %{ {? {+; @record_field } {? ; } } %} {? as @ident } }
2525
record_field ::= {* #[ {+, @attribute } ] } @name {? @field_spec } {? %| @natural } {? @decl_notations }
26-
field_spec ::= {* @binder } @of_type_inst
27-
| {* @binder } := @term
28-
| {* @binder } @of_type_inst := @term
26+
field_spec ::= @binders @of_type_inst
27+
| @binders @of_type_inst := @term
28+
| @binders := @term
2929
of_type_inst ::= {| : | :> | :: | ::> } @type
3030

3131
Defines a non-recursive record type, creating projections for each field
@@ -262,7 +262,7 @@ Constructing records
262262
263263
.. prodn::
264264
term_record ::= %{%| {? {+; @field_val } {? ; } } %|%}
265-
field_val ::= @qualid {* @binder } := @term
265+
field_val ::= @qualid @binders := @term
266266

267267
Instances of record types can be constructed using either *record form*
268268
(:n:`@term_record`, shown here) or *application form* (see :n:`@term_application`)

doc/sphinx/language/core/variants.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ the type is a :gdef:`recursive type`, in which case it can be either
2525
is reserved for non-recursive types. Natural numbers, lists or streams cannot
2626
be defined using :cmd:`Variant`.
2727

28-
.. cmd:: Variant @ident_decl {* @binder } {? %| {* @binder } } {? : @type } := {? {? %| } {+| @constructor } } {? @decl_notations }
28+
.. cmd:: Variant @ident_decl @binders {? %| @binders } {? : @type } := {? {? %| } {+| @constructor } } {? @decl_notations }
2929

3030
Defines a variant type named :n:`@ident` (in :n:`@ident_decl`)
3131
with the given list of constructors.

doc/tools/docgram/common.edit_mlg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,6 @@ SPLICE: [
22982298

22992299
| preident
23002300
| lpar_id_coloneq
2301-
| binders
23022301
| check_module_types
23032302
| decl_sep
23042303
| function_fix_definition (* loses funind annotation *)

0 commit comments

Comments
 (0)