[Haskell-cafe] Inverting a Monad

Luke Palmer lrpalmer at gmail.com
Wed Feb 6 07:04:13 EST 2008


On Feb 6, 2008 11:32 AM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> The following obviously doesn't work:
>
> inv m = (m >> mzero) `mplus` return ()
>
> because it will always return ().

How about:

  inv m = do
    success <- (m >> return True) `mplus` return False
    if success then mzero else return ()

Luke


More information about the Haskell-Cafe mailing list