Zulip Chat Archive

Stream: new members

Topic: match loses something


A. (Jan 23 2025 at 10:00):

I'm a little surprised that this doesn't just work*

def last {α : Type} (a : Array α) : Option α :=
  match a.size with
  | 0 => none
  | m + 1 => some a[m]

The match docstring says

If used as match h : e, ... with | p, ... => f | ...h : e = p is available within f.

What am I missing?

Markus Himmel (Jan 23 2025 at 10:01):

You need to give a name to the hypothesis:

def last {α : Type} (a : Array α) : Option α :=
  match h : a.size with
  | 0 => none
  | m + 1 => some a[m]

A. (Jan 23 2025 at 10:01):

Thanks!


Last updated: May 02 2025 at 03:31 UTC