[Haskell-cafe] Inverting a Monad

Felipe Lessa felipe.lessa at gmail.com
Wed Feb 6 07:16:06 EST 2008


On Feb 6, 2008 10:04 AM, Luke Palmer <lrpalmer at gmail.com> wrote:
> How about:
>
>   inv m = do
>     success <- (m >> return True) `mplus` return False
>     if success then mzero else return ()

Prelude Control.Monad> inv []
[()]
Prelude Control.Monad> inv [10]
[()]

-- 
Felipe.


More information about the Haskell-Cafe mailing list