Pattern matching articles/explanations

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 Or is it primarily to indicate to the coder that xs is useless? 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?

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

On 2007-08-16, Neil Mitchell
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
And to the compiler that the name won't be used, so it needn't warn you about not using it. -- Aaron Denney -><-
participants (3)
-
Aaron Denney
-
Ian Duncan
-
Neil Mitchell