This is perhaps a very basic question, but, nevertheless, it does not seem to have been covered on SO.
I recently took up Haskell and up until now type declarations consisted of mostly the following:
Int
Bool
Float
etc, etc
Now I am getting into lists and I am seeing type declarations that use a
, such as in the following function that iterates through an associative list:
contains :: Int -> [(Int,a)] -> [a]
contains x list = [values | (key,values)<-list, x==key]
Can someone provide an explanation as to what this a
is, and how it works? From observation it seems to represent every type. Does this mean I can input any list of any type as parameter?
a
is not special: any lower-case identifier means that. It's a type variable, and it's possible for multiple different type variables to exist in the same signature. For example,const :: a -> b -> a
takes in two arguments, each of any type at all, and returns a value with the same type as its first input. – Weasel