RFC: Custom anonymous constructor syntax and structure construction
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Proposal
Over at Mathlib we often run into the following situation (see Example below):
- A general definition
GeneralDefwith constructor. - A specialised definition
SpecialDefwhich is a special case (sayα := Bool), saydef SpecialDef := GeneralDef (α := Bool). - Then we need specialised projections and constructor(s) for
SpecialDef, often namedSpecialDef.mk
I propose:
- We enable some syntax to prioritise the special constructor
SpecialDef.mkso that we can use⟨a, b, c⟩to meanSpecialDef.mk a b c. - We make this work with
whereas well.
For example, we now have @[eliminator] to indicate the preferred recursor that the tactics cases and induction use.
Example
- CategoryTheory.Limits.Cone is the general definition.
- CategoryTheory.Limits.PullbackCone is a special case.
- CategoryTheory.Limits.PullbackCone.mk is the custom constructor.
Community Feedback
- #lean4 > Custom Constructor
- #mathlib4 > Custom structure constructors with
wherewhere another syntaxwhere (mk := name)is discussed.
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposal and its linked Zulip discussions on custom constructors and where syntax, then inspect the existing @[eliminator] feature referenced in the issue. Done would require an agreed syntax and implementation that supports prioritised anonymous constructors and structure construction with where, including the PullbackCone-style example.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100