RFC: `let` notation inside declaration binders
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Proposal
Currently, Lean provides
def foo (x y : Nat) : Nat := x + y
as notation for
def foo : ∀ x y : Nat, Nat := fun x y => x + y
This RFC suggests extending this with
def bar (x : Nat) (let y : Nat := 2) : Nat := x + y
as notation for
def bar : ∀ x : Nat, let y : Nat := 2; Nat := fun x => let y : Nat := 2; x + y
Rocq already has this notation, as (y := 2). This notation is already claimed by optParams in Lean, but (let y := 2) seems like a natural alternative.
Motivation:
- Accidental use of
optParams is a common trap (https://github.com/trishullab/PutnamBench/issues/166); theletsyntax could be referenced in the docstring ofoptParamto help resolve confusion - Allowing theorem signatures to represent
letEin addition toforallEmeans that they can now completely capture any intermediate goal state in a proof, allowing mathlib'sextract_goalto more faithfully extract the current goal with an identical local context at the start of the proof.
Optional extensions that this RFC is neutral on:
- Allow
letbinders asfun x (let y := 2 * x) (z : Fin y) => z.val - Allow
letbinders ashave foo (x : Nat) (let y : Nat := 2) := - Allow
letbinders inExistsand other custom binder types def foo (x : Nat) (open scoped Nat) (y : Fin (x)!)and similar forset_option
Community Feedback
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's let binder examples and review the linked older Zulip discussion. The issue names no implementation entry point or tests, and the optional extensions leave the scope open; done would require an agreed design and corresponding compiler support.
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
- 32/100