jhegedus
jhegedus

Reputation: 20653

Functor definition in Haskell and its explanation in Learn You a Haskell is confusing

The excerpt below from 'Learn You a Haskell' says that f is used as the 'type of a value' in a function.

What does this mean ? I.e what does 'type of a value' mean ?

Int is a 'type of a value' right ? But Maybe is not a 'type of a value' ?

Are Int and Maybe both 'type of a value' ?

Would it not be more correct to say that f a is used as a 'type of a value' in the function?

So if f would be Maybe then Maybe itself is not any type of any value ? Right ?

Only Maybe a can be a 'type of a value'?

enter image description here

Upvotes: 3

Views: 198

Answers (3)

Roman Cheplyaka
Roman Cheplyaka

Reputation: 38708

I think that sentence was intended to be interpreted in a different way.

«We know it [f] must produce a concrete type [i.e. when f is applied to a type, say a, the result of this application, f a, is a concrete type], because it [f a] is used as the type of a value [the value being the return value of fmap] in a function.»

f itself is not a type of a value, of course.

Upvotes: 9

chi
chi

Reputation: 116139

It means that fmap takes as its second argument a value of type f a. Hence, the functor f is magging types (a) to types (f a). For instance, Maybe maps Int to Maybe Int. Also, [] maps Char to [Char]. Both Maybe and [] are functors.

Note that Maybe is not a type. Maybe Int is.

Upvotes: 0

Ankur
Ankur

Reputation: 33637

The text is basically trying to give a description about how to figure out the Kind of a type variable in a type class definition.

f is the type variable and you may think I can put any type here like Int but then when you look at the type of fmap function inside the type class you see that f is used along with another type variable a and b, which indicate that you cannot use a type like Int as Int doesn't take another type to give you a new type i.e its kind is *. Hence we can say that the kind of f is * -> * i.e it take a type and give you a type back.

The highlighted text says that f b must be a concrete type because it is used as a parameter (f b as return type) for the function.

I would suggest you to read about Kinds

Upvotes: 1

Related Questions