Skip to content

Add "& T" syntax for anonymous binder "(_ : T)" and "of _ & _ & _" syntax for constructors#21611

Merged
coqbot-app[bot] merged 2 commits intorocq-prover:masterfrom
proux01:of-ampersand
Feb 26, 2026
Merged

Add "& T" syntax for anonymous binder "(_ : T)" and "of _ & _ & _" syntax for constructors#21611
coqbot-app[bot] merged 2 commits intorocq-prover:masterfrom
proux01:of-ampersand

Conversation

@proux01
Copy link
Contributor

@proux01 proux01 commented Feb 10, 2026

@proux01 proux01 added this to the 9.3+rc1 milestone Feb 10, 2026
@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 10, 2026
@proux01 proux01 added the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 10, 2026
@coqbot-app coqbot-app bot removed request: full CI Use this label when you want your next push to trigger a full CI. needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. labels Feb 10, 2026
@proux01 proux01 added kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. part: gallina The gallina commands labels Feb 10, 2026
@SkySkimmer
Copy link
Contributor

Do we really want Check (fun x of nat => x:bool). and so on to be accepted?

@SkySkimmer
Copy link
Contributor

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)

@proux01 proux01 added the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 10, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 10, 2026
@proux01
Copy link
Contributor Author

proux01 commented Feb 10, 2026

Do we really want Check (fun x of nat => x:bool). and so on to be accepted?

Yes (of course not with nat but think about phantom types for instance), combinations like & A of B & C are more dubious though, we could enfore that of can only be used at the beginning.

@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Feb 10, 2026
@proux01 proux01 added the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 10, 2026
@SkySkimmer
Copy link
Contributor

Yes

Really? You don't think that fun x of nat => seems like it should mean fun (x : nat) => but actually means fun (x : _) (_ : nat) =>?

@coqbot-app coqbot-app bot removed request: full CI Use this label when you want your next push to trigger a full CI. needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. labels Feb 10, 2026
@proux01
Copy link
Contributor Author

proux01 commented Feb 10, 2026

No (it's not fun x of type nat =>)

@SkySkimmer
Copy link
Contributor

You don't think that of sounds like it's connecting x and nat?

@gares
Copy link
Member

gares commented Feb 10, 2026

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.

@proux01 proux01 added the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 11, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 11, 2026
@proux01
Copy link
Contributor Author

proux01 commented Feb 11, 2026

You don't think that of sounds like it's connecting x and nat?

No, fun and of are both "keywords" (colored the same way by my editor) making of "match" with fun rather than x.

We use that notation in HB, nobody complained.

it is even more widely used in the mathcomp ecosystem for long, including code not developed by the usual mathcomp team.

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.

Technically, Gaëtan may be right that we don't strictly need to register of as a keyword (CI will confirm). Whether it is the right thing to do, I don't know.

@SkySkimmer
Copy link
Contributor

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.

@proux01 proux01 added the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 18, 2026
@coqbot-app coqbot-app bot removed the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 18, 2026
@proux01
Copy link
Contributor Author

proux01 commented Feb 18, 2026

Did anyone consider not using of in the first place? That is, just use fun x & nat => instead?

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.

Maybe a bit strange that we can still write C & foo of bar for constructors (IIUC) but probably nobody does that

Yes, I thought about that, but forbidding it would bring non negligible complexification/duplication in mlgs, so probably not worth it.

aleksnanevski pushed a commit to imdea-software/fcsl-pcm that referenced this pull request Feb 18, 2026
@proux01 proux01 changed the title Add "of _ & _ & _" syntax for constructors Add "& T" syntax for anonymous binder "(_ : T)" and "of _ & _ & _" syntax for constructors Feb 18, 2026
proux01 added a commit to math-comp/analysis that referenced this pull request Feb 18, 2026
proux01 added a commit to math-comp/finmap that referenced this pull request Feb 18, 2026
proux01 added a commit to math-comp/odd-order that referenced this pull request Feb 18, 2026
proux01 added a commit to math-comp/hierarchy-builder that referenced this pull request Feb 18, 2026
proux01 added a commit to proux01/Mtac2 that referenced this pull request Feb 19, 2026
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Feb 22, 2026
arthuraa added a commit to arthuraa/deriving that referenced this pull request Feb 22, 2026
CohenCyril added a commit to math-comp/math-comp that referenced this pull request Feb 22, 2026
Janno added a commit to Mtac2/Mtac2 that referenced this pull request Feb 26, 2026
proux01 and others added 2 commits February 26, 2026 11:27
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>
@proux01 proux01 added the request: full CI Use this label when you want your next push to trigger a full CI. label Feb 26, 2026
@coqbot-app coqbot-app bot removed needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. request: full CI Use this label when you want your next push to trigger a full CI. labels Feb 26, 2026
@SkySkimmer
Copy link
Contributor

@coqbot merge now

@coqbot-app coqbot-app bot merged commit 9e35cdb into rocq-prover:master Feb 26, 2026
7 of 9 checks passed
@proux01
Copy link
Contributor Author

proux01 commented Feb 26, 2026

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. part: gallina The gallina commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants