
With side effect, they are not the same.
Viktor's nested-if does not trigger unnecessary IO action, while liftA2 does.
On Mon, May 27, 2019 at 5:38 PM Jack Kelly
Viktor Dukhovni
writes: On May 27, 2019, at 1:07 AM, Magicloud Magiclouds
wrote: ``` status <- ioOperation -- IO-ed anyway return $ pureComputing || (status && pure2) ```
With two helpers:
(<&&>) :: IO Bool -> IO Bool -> IO Bool (<&&>) ma mb = ma >>= (\a -> if not a then return False else mb)
(<||>) :: IO Bool -> IO Bool -> IO Bool (<||>) ma mb = ma >>= (\a -> if a then return True else mb)
These generalise to any Applicative, I think:
import Control.Applicative (liftA2)
(<&&>) = liftA2 (&&) (<||>) = liftA2 (||)
-- Jack _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.