Reputation: 20653
The excerpt below from Gentle Intro to Haskell implies that head's type can be seen as a->a. Is it me who does not understand something or is this a typo?
Probably its just me but then how can head's type be a->a ?
An expression's or function's principal type is the least general type that, intuitively, "contains all instances of the expression". For example, the principal type of head is [a]->a; [b]->a, a->a, or even a are correct types, but too general, whereas something like [Integer]->Integer is too specific.
Upvotes: 5
Views: 131
Reputation: 53901
This is a typo, I believe they meant
head :: b -> a
since b
is just a random type variable which would unify with [a]
.
So in order of increasing specificity,
head :: [a] -> a
head :: foo -> a
head :: a
Upvotes: 9