[Haskell-cafe] How to make boolean logic with IO Monad more expressive?
Viktor Dukhovni
ietf-dane at dukhovni.org
Mon May 27 17:29:50 UTC 2019
On Mon, May 27, 2019 at 05:46:11AM -0400, Viktor Dukhovni wrote:
> The generalized Monadic version will short-circuit.
>
> (<&&>) :: Monad m => m Bool -> m Bool -> m Bool
> (<&&>) ma mb = ma >>= (\a -> if not a then return False else mb)
>
> (<||>) :: Monad m => m Bool -> m Bool -> m Bool
> (<||>) ma mb = ma >>= (\a -> if a then return True else mb)
I should mention that a compatible even better generalized interface
is available via Control.Selective:
(<||>): http://hackage.haskell.org/package/selective-0.2/docs/Control-Selective.html#v:-60--124--124--62-
(<&&>): http://hackage.haskell.org/package/selective-0.2/docs/Control-Selective.html#v:-60--38--38--62-
--
Viktor.
More information about the Haskell-Cafe
mailing list