[Haskell-cafe] Pattern matching articles/explanations

Neil Mitchell ndmitchell at gmail.com
Thu Aug 16 17:27:49 EDT 2007


Hi

> So what I noticed that "A Gentle Introduction to Haskell" mentioned
> that wild-cards are useful in constructors. For example:
>
> head (x:_) = x
>
> So, does that offer any performance benefits over:
>
> head (x:xs) = x

No. They are exactly the same. _ simply means "a new unique name".

> Or is it primarily to indicate to the coder that xs is useless?

Yes

> I get
> the impression it has a very similar meaning to the irrefutable
> pattern in regards to not evaluating it when the function is called.
> Or am I way off?

Way off :-) Nothing to do with irrefutable patterns, or demand of
evaluation, its got two uses:

1) Indicate to the reader that this argument is never used
2) Save you coming up with a name for the argument

Thanks

Neil


More information about the Haskell-Cafe mailing list