[Haskell-cafe] How to make boolean logic with IO Monad more expressive?

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Mon May 27 09:14:05 UTC 2019


Cool. Thanks.

On Mon, May 27, 2019 at 5:10 PM Viktor Dukhovni <ietf-dane at dukhovni.org> wrote:
>
>
>
> > On May 27, 2019, at 1:07 AM, Magicloud Magiclouds <magicloud.magiclouds at gmail.com> 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)
>
> you'd write:
>
>   pure preComputing <||> (ioOperation <&&> pure pure2)
>
> You could even define suitable fixity to make <&&> have higher
> precedence than <||> and not need any parentheses.
>
> --
>         Viktor.
>
> _______________________________________________
> 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.


More information about the Haskell-Cafe mailing list