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

Chris Wong lambda.fairy at gmail.com
Thu Nov 13 10:52:21 UTC 2014


> Applicative and monadic composition *should* be the same, given that
> Applicative contains the law
>
>     (<*>) = ap

Ah, I probably wasn't too clear with that last comment. What I meant by
"applicative and monadic composition don't always yield the same result" is
that

    Compose m Maybe

and

    MaybeT m

are *not* interchangeable, despite their unwrapped types being the same. As
you point out, the latter short-circuits but the former does not.

I guess a better wording is that there is often more than one way to
compose things.

(Compose is from Data.Functor.Compose in the transformers package.)

Chris

> And in fact if we rewrite Andras solution as
>
>     try a b = (<|>) <$> a <*> b
>
> It is still broken.
>
> The fact that you find libraries where (<*>) is not ap has been
> confusing for me as well :P.
>
> Evan's `try` doesn't use Applicative at all, but short-circuits
> manually.  For this kind of stuff I usually use MaybeT.
>
> Francesco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141113/6b0b9878/attachment.html>


More information about the Haskell-Cafe mailing list