[Haskell-cafe] Inverting a Monad

Tillmann Rendel rendel at rbg.informatik.tu-darmstadt.de
Wed Feb 6 14:27:03 EST 2008


Bas van Dijk wrote:
> The following obviously doesn't work:
> 
> import Control.Monad.Error
> 
> inv :: MonadError e m => m a -> m ()
> inv m = (m >> fail "") `catchError` \_ -> (return ())

What about this?

inv :: MonadError e m => m a -> m ()
inv m = join $ (m >> return mzero) `catchError` \_ -> return (return ())

   Tillmann


More information about the Haskell-Cafe mailing list