[Haskell-cafe] Very Small Program
Jason Dagit
dagit at codersbase.com
Thu Nov 2 12:32:10 EST 2006
On 11/2/06, ajb at spamcop.net <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.
Actually, I had to try it out to see if it would work. That's a neat
little trick. I had known that this similar one worked but it uses
pattern matching on a data constructor so I never questioned it:
numJusts xs = sum [ 1 | Just x <- xs ]
thanks,
Jason
More information about the Haskell-Cafe
mailing list