Zulip Chat Archive

Stream: new members

Topic: what is α


J. O. (Jan 26 2022 at 20:42):

so i have this code:

def maxList (list: List Nat) : Option Nat :=
    List.maximum? list

def callMaxList (list: α) :=
    maxList list

this code gives the error

application type mismatch
  maxList list
argument
  list
has type
  α : Sort ?u.63
but is expected to have type
  List Nat : Type

what is α exactly? i thought it was like some generic type, but im starting to reconsider

Yaël Dillies (Jan 26 2022 at 20:44):

Yes, precisely. It is a generic type, and you gave it somewhere where Nat was expected.

Yaël Dillies (Jan 26 2022 at 20:44):

A generic type is usually not Nat!

J. O. (Jan 26 2022 at 20:44):

then what is it?

Reid Barton (Jan 26 2022 at 20:44):

More importantly, a general type is not a list

J. O. (Jan 26 2022 at 20:45):

why isnt the generic type doing its job

Yaël Dillies (Jan 26 2022 at 20:45):

It doesn't try to unify, if that's what you mean.

J. O. (Jan 26 2022 at 20:45):

Reid Barton said:

More importantly, a general type is not a list

what do you mean?

Reid Barton (Jan 26 2022 at 20:46):

The actual definition of callMaxList is something like def callMaxList {α : Type} (list: α) := maxList list. α is a variable that can be provided by the user of your function callMaxList, and they could choose something like α = Bool. In that case list : Bool and so maxList list doesn't make sense.

Yaël Dillies (Jan 26 2022 at 20:47):

α : Type means that you can replace α with any type after you've defined your function. But you're trying to do the opposite, make Lean replace α with Nat.

Reid Barton (Jan 26 2022 at 20:48):

What you maybe want is not an actual variable list: α but a metavariable list: _, meaning "Lean please figure out what should go here".

Reid Barton (Jan 26 2022 at 20:48):

Although, it would usually be better to just say what should go there.

J. O. (Jan 26 2022 at 20:49):

Yaël Dillies said:

α : Type means that you can replace α with any type after you've defined your function. But you're trying to do the opposite, make Lean replace α with Nat.

ah i see

Kyle Miller (Jan 26 2022 at 20:49):

I know you're familiar with f#, and I think you can think of your second definition as doing let callMaxList<'a> (list : List<a>) := maxList list (I probably got the syntax wrong). This is a type error since maxList expects a List<Nat>, not a generic List<a>.

Yaël Dillies (Jan 26 2022 at 20:49):

Nor a generic <a>!

J. O. (Jan 26 2022 at 20:49):

Kyle Miller said:

I know you're familiar with f#, and I think you can think of your second definition as doing let callMaxList<'a> (list : List<a>) := maxList list (I probably got the syntax wrong). This is a type error since maxList expects a List<Nat>, not a generic List<a>.

that makes sense

J. O. (Jan 26 2022 at 20:50):

you would have to give the type

J. O. (Jan 26 2022 at 20:51):

i have another type related question. so I was reading the manual, and came across

def p1 (a b c d : Nat) : Prop :=
  (a + b)^c  d

def p2 (i j k : Int) : Prop :=
  i % (j * k) = 0

why are the return types of these two functions Prop instead of Bool?

Yaël Dillies (Jan 26 2022 at 20:51):

because that would require them to be decidable, which is more information

Yaël Dillies (Jan 26 2022 at 20:52):

but they could have been

J. O. (Jan 26 2022 at 20:52):

what do you mean by "decidable"? and what does Prop do to the return type?

Kyle Miller (Jan 26 2022 at 20:52):

A handwavey answer: a Prop is like a Bool that knows what it is that's supposed to be true or false.

J. O. (Jan 26 2022 at 20:52):

why is that useful?

J. O. (Jan 26 2022 at 20:52):

especially in these two functions?

J. O. (Jan 26 2022 at 20:53):

and why is it in numbers and not booleans image.png


Last updated: Dec 20 2023 at 11:08 UTC