Normally, this is not possible. You can do something like
a `par` b `pseq` (a && b)
but if b
evaluates to False
, 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
-- | Turn a binary commutative operation into one that tries both orders in
-- parallel. Useful when there are special cases that don't require
-- evaluating both arguments.
-- ...
parCommute :: (a -> a -> b) -> a -> a -> b
and also directly defines pand
,por
and other similar commutative functions, such that
pand undefined False -> False
pand False undefined -> False