Add "& T" syntax for anonymous binder "(_ : T)" and "of _ & _ & _" syntax for constructors#21611
Conversation
31a92a4 to
d88cf26
Compare
|
Do we really want |
|
We could do something constructor specific instead with modified vernac/g_vernac.mlg
@@ -639,9 +639,16 @@ GRAMMAR EXTEND Gram
{ (oc,(idl,c)) } ] ]
;
+ constructor_binders: [[
+ l = binders -> { l }
+ | IDENT "of"; l = LIST1 term LEVEL "99" SEP "&" -> {
+ List.map (fun c -> CLocalAssum ([CAst.make ~loc Anonymous], None, Default Explicit, c)) l
+ }
+ ]];
+
constructor_type:
- [[ l = binders;
- t= [ coe = of_type_inst; c = lconstr ->
+ [[ l = constructor_binders;
+ t = [ coe = of_type_inst; c = lconstr ->
{ fun l attr id -> ((attr, fst coe, snd coe),(id,mkProdCN ~loc l c)) }
| ->
{ fun l attr id -> ((attr,NoCoercion,NoInstance),(id,mkProdCN ~loc l (CAst.make ~loc @@ CHole (None)))) } ](and then "of" doesn't need to be keyword AFAICT) |
d88cf26 to
fa49a48
Compare
Yes (of course not with |
fa49a48 to
d88cf26
Compare
Really? You don't think that |
d88cf26 to
08b6d7d
Compare
|
No (it's not |
|
You don't think that |
|
We use that notation in HB, nobody complained. Said that, I think of needs to be a keyword if you want that to work, even in constructors we use it after some initial binders as in K x of x != 0, IIRC. |
08b6d7d to
da652b2
Compare
No,
it is even more widely used in the mathcomp ecosystem for long, including code not developed by the usual mathcomp team.
Technically, Gaëtan may be right that we don't strictly need to register |
|
It doesn't need to be a keyword in my proposed diff where it only works if used immediately after the constructor name, which doesn't support the example @gares gave. |
d810143 to
d99fd86
Compare
The overlay cost on ssreflect users is not totally negligible (for instance: 410 lines in MathComp, 167 lines in Analysis, 151 lines in HB,...) but was deemed acceptable, so let's go for that.
Yes, I thought about that, but forbidding it would bring non negligible complexification/duplication in mlgs, so probably not worth it. |
e.g.: Variant t := C1 of a & b & c | C2 x y of P x & Q y. Co-authored-by: Gaëtan Gilbert <gaetan.gilbert@skyskimmer.net>
d99fd86 to
af52fac
Compare
|
@coqbot merge now |
|
Thanks |
New syntactic sugar
& Tfor anonymosu binder(_ : T)andof T & ... & Tfor constructors, enabling theVariant t := C1 of a & b & c | C2 x y of P x & Q y.syntax. This adds the new reserved keywordof.This implements an old Coq call decision: https://github.com/rocq-prover/rocq/wiki/Coq-Call-2023-10-24 (just took me some time to get to it)
Documented any new / changed user messages.make doc_gram_rsts.Overlays (to be merged before the current PR)