Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the type of head be a->a?

Tags:

haskell

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.

like image 747
jhegedus Avatar asked Mar 29 '14 23:03

jhegedus


People also ask

What are the 4 types of headaches?

There are several hundred types of headaches, but there are four very common types: sinus, tension, migraine, and cluster. Headaches are always classified as either primary or secondary.

What are the different parts of head?

A head is the part of an organism which usually includes the ears, brain, forehead, cheeks, chin, eyes, nose, and mouth, each of which aid in various sensory functions such as sight, hearing, smell, and taste.

Why do my head hurts everyday?

Conditions that might cause nonprimary chronic daily headaches include: Inflammation or other problems with the blood vessels in and around the brain, including stroke. Infections, such as meningitis. Intracranial pressure that's either too high or too low.


1 Answers

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
like image 109
Daniel Gratzer Avatar answered Oct 11 '22 13:10

Daniel Gratzer