Zulip Chat Archive

Stream: lean4

Topic: Naming equality hypothesis in match branch


Adam Topaz (Dec 14 2023 at 17:14):

Consider the following:

def test : List Nat  Unit
  | [] => .unit
  | t@(x :: xs) =>
    /-
    t: List Nat
    x: Nat
    xs: List Nat
    h✝: t = x :: xs
    ⊢ Unit
    -/
    sorry

In the second branch, t@(x :: xs), do we have some convenient way to name the hypothesis h✝: t = x :: xs?

Shreyas Srinivas (Dec 14 2023 at 17:21):

yes we do

Shreyas Srinivas (Dec 14 2023 at 17:22):

def test (k : List Nat) : Unit :=
  match h : k with
  | [] => .unit
  | t@(x :: xs) =>
    /-
    t: List Nat
    x: Nat
    xs: List Nat
    h✝: t = x :: xs
    ⊢ Unit
    -/
    sorry

Adam Topaz (Dec 14 2023 at 17:22):

no, that doesn't answer my actual question.

Adam Topaz (Dec 14 2023 at 17:22):

That gives a hypothesis h : k = x :: xs, not t = x :: xs.

Shreyas Srinivas (Dec 14 2023 at 17:24):

Oh okay. Apologies for misunderstanding the question

Eric Wieser (Dec 14 2023 at 18:05):

I think the answer is no

Eric Wieser (Dec 14 2023 at 18:06):

Oh, the comment is wrong!

def test : List Nat  Unit
  | [] => .unit
  | t@ht : (x :: xs) =>
    sorry

Adam Topaz (Dec 14 2023 at 18:06):

aha!

Eric Wieser (Dec 14 2023 at 18:07):

(guessed from here)

Eric Wieser (Dec 14 2023 at 18:11):

Comment is fixed in lean4#3073

Kevin Buzzard (Dec 14 2023 at 18:27):

I've seen plenty of this but this is the first time I've seen th@t. Oh, sorry, t@ht.

Adam Topaz (Dec 14 2023 at 18:45):

I'm happy such a syntax exists, but my first guess would have been ht:t@(x :: xs).

Utensil Song (Dec 18 2023 at 01:57):

What does @ mean in general? I can't really parse it with : in my mental model :joy:

Yury G. Kudryashov (Dec 18 2023 at 02:06):

BTW, what's the rationale behind these equalities no longer being definitional? In Lean 3, it was possible to use t as a short name for x :: xs.

Thomas Murrills (Dec 18 2023 at 03:46):

Utensil Song said:

What does @ mean in general? I can't really parse it with : in my mental model :joy:

In patterns, @ lets you name terms while still destructuring them: | a@(x :: xs) => body matches x :: xs and binds x and xs as usual, but also gives the whole thing the name a.

That’s why this syntax is weird: you’d expect t@ht : x :: xs to name…just ht, I suppose? Even t@(ht : x :: xs) would look wrong, since t is the name for x :: xs, not some ht. (And ht doesn’t really have type x :: xs, of course, so we’re using a lot of notation differently here.)


Last updated: Dec 20 2023 at 11:08 UTC