Zulip Chat Archive

Stream: lean4

Topic: Destructuring in function definition


Patrick Massot (Oct 24 2025 at 20:29):

This was probably discussed before but I can’t find it. Is there a reason why fun (⟨x, y⟩ : X × Y) ↦ whatever x y generates fun p ↦ match p with | ⟨x, y⟩ => whatever x y instead of fun p ↦ whatever p.1 p.2?

Patrick Massot (Oct 24 2025 at 20:29):

Bonus question: does anyone want to have fun writing a simpproc that turns the match version into the other version?

Aaron Liu (Oct 24 2025 at 20:31):

Patrick Massot said:

Bonus question: does anyone want to have fun writing a simpproc that turns the match version into the other version?

does dsimp only not work?

Patrick Massot (Oct 24 2025 at 20:38):

It does nothing.

Aaron Liu (Oct 24 2025 at 20:39):

that's weird, I remember it doing something for me before

Yury G. Kudryashov (Oct 25 2025 at 01:55):

In my examples simp only simplifies this match. Do you have an #mwe? E.g., this works:

example (f : Nat × Nat  Nat) (hf : f = fun (x, y) => x + y) : f (0, 0) = 0 := by
  simp only at hf
  guard_hyp hf : f = fun x => x.1 + x.2
  sorry

Bhavik Mehta (Oct 25 2025 at 02:11):

dsimp only works in this example too

Patrick Massot (Oct 26 2025 at 11:22):

Sorry about disappearing, I was travelling yesterday. We’re not talking about the same thing. I’m talking about

example : Nat := by
  let g := fun (x, y : Nat × Nat)  x + y
  simp only at g
  sorry

Patrick Massot (Oct 26 2025 at 11:23):

The simp only does nothing there.

Kenny Lau (Oct 26 2025 at 11:24):

example : 0 + 0 = 0 := by simp

example : True := by
  let g : Nat := 0 + 0
  simp at g

but simp doesn't change lets

Patrick Massot (Oct 26 2025 at 11:32):

I agree, so we need something to fix this issue.

Kenny Lau (Oct 26 2025 at 11:34):

but my example shows that this isn't about function, this is about the behaviour of simp on let

Patrick Massot (Oct 26 2025 at 11:43):

I understand, but I think there are not so many cases where you want to use let only to immediately wish dsimp could act on it.

Yury G. Kudryashov (Nov 02 2025 at 19:29):

I guess, we can have something like simp% and/or dsimp% for these cases.

Eric Wieser (Nov 02 2025 at 21:53):

It still would be nice to be able to use rw, simp etc on the values of lets, even if indeed it usually isn't useful in polished code.

Eric Wieser (Nov 02 2025 at 21:54):

I think the answer to Patrick's original question is that fun patterns are intended to be a very simple wrapper around match syntax

Eric Wieser (Nov 02 2025 at 21:55):

And so without complicating the wrapper, I guess the question is why match p with Prod.mk x y => f x y isn't syntax for f p.1 p.2.


Last updated: Dec 20 2025 at 21:32 UTC