[Haskell-cafe] pattern matching instead of prelude.head

Albert Y. C. Lai trebla at vex.net
Fri Sep 16 23:34:12 CEST 2011

On 11-09-15 10:24 PM, Michael Litchard wrote:
> Someone commented on StackOverflow that pattern matching the first
> element of a list was preferable to head. This makes sense
> intuitively. Could someone articulate the reason why this is true?

if null s then e0 else ...(head s)...(tail s)...

is a clumsy way to say

case s of
   [] -> e0
   h:t -> ...h...t...

The clumsy way is more familiar because it is popularized by lisp. It is 
the way in lisp because lisp is old.

More information about the Haskell-Cafe mailing list