[Haskell-cafe] Access to list

2008-01-13 Thread Fernando Rodriguez
Hi, 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: interactive:1:9: No instance for (Num [a]) arising from the literal `3' at interactive:1:9 Possible fix:

Re: [Haskell-cafe] Access to list

2008-01-13 Thread jerzy . karczmarczuk
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

Re: [Haskell-cafe] Access to list

2008-01-13 Thread Jed Brown
On 13 Jan 2008, [EMAIL PROTECTED] wrote: If I define the follwoing functions: car (x:_) = x car [] = [] This won't typecheck. It helps to add a type signature car :: [a] - a The first element of an empty list is undefined, so you can do what Prelude.head does and write: car [] =

Re: [Haskell-cafe] Access to list

2008-01-13 Thread Tom Phoenix
On Jan 13, 2008 7:55 AM, Fernando Rodriguez [EMAIL PROTECTED] wrote: If I define the follwoing functions: car (x:_) = x car [] = [] What's the type signature for that function? Cheers! --Tom Phoenix ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Access to list

2008-01-13 Thread Felipe Lessa
On Jan 13, 2008 2:07 PM, Tom Phoenix [EMAIL PROTECTED] wrote: On Jan 13, 2008 7:55 AM, Fernando Rodriguez [EMAIL PROTECTED] wrote: If I define the follwoing functions: car (x:_) = x car [] = [] What's the type signature for that function? car :: [[a]] - [a] -- Felipe.

Re: [Haskell-cafe] Access to list

2008-01-13 Thread jerzy . karczmarczuk
Jed Brown writes: On 13 Jan 2008, [EMAIL PROTECTED] wrote: If I define the follwoing functions: car (x:_) = x car [] = [] This won't typecheck. It helps to add a type signature car :: [a] - a Good will, wrong diagnosis. This WILL check. car :: forall a. [[a]] - [a] J.