leanprover / leanprover/lean4

RFC: Custom anonymous constructor syntax and structure construction

Open
#10,412 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-medium RFC
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):

  1. A general definition GeneralDef with constructor.
  2. A specialised definition SpecialDef which is a special case (say α := Bool), say def SpecialDef := GeneralDef (α := Bool).
  3. Then we need specialised projections and constructor(s) for SpecialDef, often named SpecialDef.mk

I propose:

  1. We enable some syntax to prioritise the special constructor SpecialDef.mk so that we can use ⟨a, b, c⟩ to mean SpecialDef.mk a b c.
  2. We make this work with where as well.

For example, we now have @[eliminator] to indicate the preferred recursor that the tactics cases and induction use.

Example
  1. CategoryTheory.Limits.Cone is the general definition.
  2. CategoryTheory.Limits.PullbackCone is a special case.
  3. CategoryTheory.Limits.PullbackCone.mk is the custom constructor.
Community Feedback
  1. #lean4 > Custom Constructor
  2. #mathlib4 > Custom structure constructors with where where another syntax where (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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.