[Haskell-cafe] Monad m => m (Maybe a) -> m (Maybe a) -> m (Maybe a)

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Tue Nov 11 17:20:35 UTC 2014


On Tue, Nov 11, 2014 at 05:18:56PM +0000, Tom Ellis wrote:
> On Tue, Nov 11, 2014 at 08:57:48AM -0800, Evan Laforge wrote:
> > try :: Monad m => m (Maybe a) -> m (Maybe a) -> m (Maybe a)
> > try action alternative = maybe alternative (return . Just) =<< action
> 
> Looks like the MonadPlus instance for MaybeT to me
> 
>     runMaybeT $ MaybeT (print "first" >> return (Just 1))
>                 `mplus` MaybeT (print "second" >> return (Just 2))
> 
>     Just 1

I mistranscribed the output.  The output is

    "first"
    Just 1


More information about the Haskell-Cafe mailing list