-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: @[flat]
annotation for names in the extend
clause of a structure
#2666
Comments
Having concrete data on which patterns help where in mathlib would be very helpful. |
This implements leanprover#2666, allowing manual tweaking of whether structure inheritance is flat or nested, without forcing the user to fallback to the `FlatHack` approach in https://arxiv.org/abs/2306.00617. This is documented via a docstring on the `flat` parser, which appear as a hover docstring as long as `Lean/Parser/Command` is imported.
This implements leanprover#2666, allowing manual tweaking of whether structure inheritance is flat or nested, without forcing the user to fallback to the `FlatHack` approach in https://arxiv.org/abs/2306.00617. This is documented via a docstring on the `flat` parser, which appear as a hover docstring as long as `Lean/Parser/Command` is imported.
This implements leanprover#2666, allowing manual tweaking of whether structure inheritance is flat or nested, without forcing the user to fallback to the `FlatHack` approach in https://arxiv.org/abs/2306.00617. This is documented via a docstring on the `flat` parser, which appear as a hover docstring as long as `Lean/Parser/Command` is imported.
This implements leanprover#2666, allowing manual tweaking of whether structure inheritance is flat or nested, without forcing the user to fallback to the `FlatHack` approach in https://arxiv.org/abs/2306.00617. This is documented via a docstring on the `flat` parser, which appear as a hover docstring as long as `Lean/Parser/Command` is imported.
This implements leanprover#2666, allowing manual tweaking of whether structure inheritance is flat or nested, without forcing the user to fallback to the `FlatHack` approach in https://arxiv.org/abs/2306.00617. This is documented via a docstring on the `flat` parser, which appear as a hover docstring as long as `Lean/Parser/Command` is imported.
In #2940, I add a |
Some initial data: used on only the |
Proposal
What?
When working with a structure hierarchy like
the type of
D.mk
is asymmetric:More precisely, the representation of
D
is to embed an entireB
structure, but then only take the parts of theC
structure that do not overlap withB
, namelyc : Unit
.I have no doubt that this behavior is useful in some circumstances, but in situations where a symmetric API is more important than performance, this behavior is annoying.
Let's imagine that the symmetric API we want is
D.mk (toA : A) (b c : Unit)
. Right now, there are the following workarounds to achieve thatD
manually withoutextends
::= { d with }
approach performs unwanted eta-expansionD.mk (toDFlatHack : DFlatHack) (toA : A) (b c : Unit) : D
, where the first argument is vacuous and can always be passed as⟨⟩
.In Lean 3 we had
set_option old_structure_cmd true
; but this was a bad design because it did not allow parent structures to selectively be flattened (among other reasons).The proposal is to remove the need for a hack here, such that the user can write
or any other reasonable syntax.
How?
The presence of
flat
simply means "skip the overlapping fields check, and behave as if the fields overlap"; that is, a check for the syntactic marker would be added to the conditions here:lean4/src/Lean/Elab/Structure.lean
Lines 423 to 428 in 57e2391
lean4/src/Lean/Elab/Structure.lean
Lines 479 to 483 in 57e2391
Why?
RingHom
, which has to pick betweenMonoidHom
andAddMonoidHom
as it's "main" parent. This affects the shape of the constructor, the simp lemmas about it, and adds ugly additional angle brackets to anonymous constructorsIn both cases, having a
@[flat]
attribute would make it vastly easier to perform performance and API experiments in mathlib to work out where nested structures help, and where they're a hindrance.Community Feedback
Mario originally proposed this syntax here.
Impact
Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: