pattern guards (was: Parallel list comprehensions)

Aaron Denney wnoise at ofb.net
Thu Feb 16 14:19:21 EST 2006


On 2006-02-16, Claus Reinke <claus.reinke at talk21.com> wrote:
>> Oh golly. I can't live without pattern guards. they are the best darn
>> thing since sliced bread. I highly recommend them. I .. would have 
>> to seriously refactor a ton of code if pattern guards disapeared.
>> 
>> So much so that it would be less work to implement pattern guards for
>> other compilers and submit the patches.
>
> eh, well, pattern guards are nice. but, many of their uses are also 
> easily replaced, by moving the pg-monad from the lhs to the rhs,
> and employing MonadPlus for the fall-throughs; something roughly 
> like:
>
>     f p1 | g1 = e1
>     ..
>     f pn | gn = en
>         where <stuff>
>
> -->
>
>     f x = fromJust $ do {p1 <- return x; guard g1; return e1}
>             ..
>             `mplus`     do {pn <- return x; guard gn; return en}
>         where <stuff>

This works, of course, but it looks far far uglier, and is harder to
type.

-- 
Aaron Denney
-><-



More information about the Haskell-prime mailing list