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

Evan Laforge qdunkan at gmail.com
Tue Nov 11 21:41:09 UTC 2014


On Tue, Nov 11, 2014 at 9:18 AM, Tom Ellis
<tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> 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))

Ah, so it looks like it does exist, but requires explicit running and
wrapping, e.g. compare to:

try (print "first" >> return (Just 1)) $ print "second" >> return (Just 2)

I guess it's like 'justm' then, which is also just MaybeT, but with less typing.

Thanks!


More information about the Haskell-Cafe mailing list