[Haskell-cafe] Intro to monad transformers

Stephen Tetley stephen.tetley at gmail.com
Sun Dec 26 20:23:34 CET 2010


> instance Monad m => MonadPlus (MaybeT m) where
>     mzero     = MaybeT $ return Nothing
>     mplus x y = MaybeT $ do maybe_value <- runMaybeT x
>                             case maybe_value of
>                                  Nothing    -> runMaybeT y
>                                  Just _ -> return maybe_value
>

I've not run it so with some caution, I'd expect this to work - the
last line is now returning the first answer with 'return' of the
wrapped monad.

I'm not sure if this is a lawful version of mplus though...



More information about the Haskell-Cafe mailing list