[Haskell-cafe] Very Small Program

ajb at spamcop.net ajb at spamcop.net
Thu Nov 2 06:21:03 EST 2006


G'day all.

Quoting Bernie Pope <bjpop at csse.unimelb.edu.au>:

> This is a weird example of a pattern binding, and it is surprising
> (to me) that the syntax is valid.

Maybe.  But you wouldn't balk at this:

    numzeroes xs = sum [ 1 | 0 <- xs ]

...even if you wouldn't naturally express it that way.  Patterns like
this are useful in places other than lets.  I'd find it more surprising
if lets were treated as a special case.

> In this case you are defining the function which is bound to the
> variable called "+".

Though thanks to n+k patterns, this is well-understood to be a
confusing and controversial case.

> One would normally expect to see at least one variable inside the
> pattern on the
> left-hand-side of a pattern binding (otherwise what point would there
> be to the
> definition?).

If the pattern is demanded (as it may well be in a list comprehension
generator, do block generator or a lambda), then it can be very useful.
The programmer is asking for an error/empty list/monad "fail" if the
conformality check fails.

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list