[Haskell-beginners] Case statements shorter

Roel van Dijk vandijk.roel at gmail.com
Tue Nov 2 05:11:54 EDT 2010

On Mon, Nov 1, 2010 at 7:23 PM, uu1101 at gmail.com <uu1101 at gmail.com> wrote:
> * _ is not a special keyword in haskell. It's a regular variable so will
> always match. It's usually used when you don't use it's value in the right
> hand side or when it adds no information. In this case its value will be n
> so there is no reason to introduce another name.

This is incorrect. _ is a pattern not a variable.

I can write

  f (_:_) = "bla"

but not

  f (x:x) = "bla"
  Conflicting definitions for `x' In the definition of `f'

So _ is a pattern that always matches but is never bound to a value.


More information about the Beginners mailing list