Zulip Chat Archive

Stream: general

Topic: inductive def


Patrick Massot (Dec 01 2018 at 18:07):

I very rarely use inductive def so I'm a bit confused by:

-- Works ok
def find :   list   bool
| a []     := ff
| a (h::t) := if (a = h) then tt else find a t

-- Lean complains: type mismatch at application  find' a, term  a has type  ℕ but is expected to have type   list ℕ
def find' (a : ) : list   bool
| []     := ff
| (h::t) := if (a = h) then tt else find' a t

Is there a way to get something like my second attempt to work?

Gabriel Ebner (Dec 01 2018 at 18:08):

find' t (without the a)

Gabriel Ebner (Dec 01 2018 at 18:14):

(The parameters before the colon---a in this case---are assumed to be constant in the recursive calls, so you don't have to repeat them.)

Kevin Buzzard (Dec 01 2018 at 18:26):

That used to confuse me so much.

inductive eq {α : Sort u} (a : α) : α  Prop
| refl : eq a

I was like "...yeah, but what is a equal to??". It's equal to the a before the colon.

Patrick Massot (Dec 01 2018 at 18:40):

Thanks!


Last updated: Dec 20 2023 at 11:08 UTC