[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:18:56 UTC 2014
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
runMaybeT $ MaybeT (print "first" >> return Nothing)
`mplus` MaybeT (print "second" >> return (Just 2))
"first"
"second"
Just 2
Tom
More information about the Haskell-Cafe
mailing list