Does haskell have a parallel "and" method
parAnd :: Bool -> Bool -> Bool
such that
(a `parAnd` b)
will spark the evaluation of a and b in parallel and return false as soon as either a or b evaluates to false (and not wait for the other one)?
Is there some way to implement such a thing?
Normally, this is not possible. You can do something like
but if
b
evaluates toFalse
,a
is still fully evaluated.However, this is possible with the unambiguous choice operator created by Conal Elliott for his Functional Reactive Programming (FRP) implementation. It's available on Hackage as unamb package and does exactly what you want. In particular, it contains
and also directly defines
pand
,por
and other similar commutative functions, such thatThis is provided by Conal Elliott's unamb package. It uses
unsafePerformIO
under the covers to evaluate botha && b
andb && a
on separate threads, and returns when either produces a result.