[Haskell-cafe] Pattern guards in comprehensions

M Farkas-Dyck strake888 at gmail.com
Mon Aug 10 15:14:58 UTC 2015


On 10/08/2015 at 08:40:43 -0400, amindfv at gmail.com wrote:
> There's an even nicer way! Use view patterns:
> 
> allMinus m ns = [ n' | ((?- m) -> Just n') <- ns ]

In this case it's not bad, but in some cases the guarded form is clearer, e.g.

f z ys = [g x y | y@(flip h z -> Just x) <- ys]

vs.

f z ys = [g x y | y <- ys, Just x <- [h y z]]

tho this is personal preference.


More information about the Haskell-Cafe mailing list