[Haskell-cafe] Access to list

Fernando Rodriguez frr149 at easyjob.net
Sun Jan 13 10:55:18 EST 2008


If I define the follwoing functions:

car (x:_) = x
car [] = []

cdr (_:xs) = xs
cdr [] = []

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' at <interactive>:1:9
    Possible fix: add an instance declaration for (Num [a])
    In the expression: 3
    In the first argument of `car', namely `[1, 2, 3]'
    In the expression: car [1, 2, 3]

What am I doing wrong this time? :-P


More information about the Haskell-Cafe mailing list