
13 Jan
2008
13 Jan
'08
11:06 a.m.
On 13 Jan 2008, frr149@easyjob.net 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 [] = undefined
cdr (_:xs) = xs cdr [] = []
This is entirely valid, but may not be what you want. cdr [] = undefined -- like Prelude.tail Jed