leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.75k stars 428 forks source link

RFC: `let` notation inside declaration binders #6091

Open eric-wieser opened 2 weeks ago

eric-wieser commented 2 weeks ago

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:

Optional extensions that this RFC is neutral on:

Community Feedback

Impact

Add :+1: to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add :+1: to it.

Kha commented 1 week ago

The simplest workaround here should be to move the relevant part of the type to the RHS of :. This means the binders have to be reintroduced in the body, but for proofs that can be done with intros so I'd say it's really not too bad. This strategy also extends to open in etc.

eric-wieser commented 6 days ago

This strategy also extends to open in etc.

Does intros really replay open in / set_option _ in clauses in binders like it does let?

Kha commented 2 days ago

It doesn't, you're right about that part