[Haskell-cafe] Access to list

jerzy.karczmarczuk at info.unicaen.fr jerzy.karczmarczuk at info.unicaen.fr
Sun Jan 13 11:06:28 EST 2008

Fernando Rodriguez writes: 

> car (x:_) = x
> car [] = []
> and try to apply them to some list, such as 
> car [1,2,3] 
> I get this odd error:
>    No instance for (Num [a])
>      arising from the literal `3' ...

The error is really a bit cryptic (who cares, Nums or whatever...)
but the error is here. Your 'car' picks the first element, or the empty
LIST. So, the first element of the argument also must be a list, not
a number, otherwise the type-checker yells. 

Jerzy Karczmarczuk 

More information about the Haskell-Cafe mailing list