[Haskell-cafe] Very Small Program

Bernie Pope bjpop at csse.unimelb.edu.au
Thu Nov 2 21:32:02 EST 2006

On 02/11/2006, at 9:56 PM, ajb at spamcop.net wrote:

> 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.

I agree with what you say. When I said "pattern binding", I was using  
terminology of the Haskell Report, which means only declarations of
the form "pat = exp". Generator statements and lambdas are a  
different story, as you
rightly point out. Nonetheless, I still believe that it is surprising  
"pattern bindings" that this syntax is allowed, since there doesn't
seem to be any purpose to them. (A cursory glance at the Report suggests
that this kind of pattern binding is allowed). Then again, since the  
are benign, maybe one could argue that it is better to have one less  
rule in
the language definition? Then again, such a declaration could be the
sign of a buggy program, and it might be better to give a compile  
time error.


More information about the Haskell-Cafe mailing list