[Haskell-cafe] Trouble with function with two clauses

Henning Thielemann lemming at henning-thielemann.de
Wed Jan 9 14:49:18 EST 2008


On Wed, 9 Jan 2008, Fernando Rodriguez wrote:

> I have the following type and function:
>
> data ConsCell a = Nil | Cons a (ConsCell a) deriving Show
> head' Nil = Nothing
> head' (Cons a _) = Just a
>
> Works fine, however, what's wrong with the following function?
>
> head''
> 	| Nil = Nothing
> 	| Cons a _ = Just a

Maybe you want

head''' x =
   case x of
      Nil      -> Nothing
      Cons a _ -> Just a


More information about the Haskell-Cafe mailing list