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

Evan Laforge qdunkan at gmail.com
Thu Nov 13 23:36:41 UTC 2014


On Thu, Nov 13, 2014 at 11:23 AM, Andras Slemmer <0slemi0 at gmail.com> wrote:
> Actually this is a great way to shed light on the difference between monadic
> and applicative: In the original function the context chaining itself
> depends on a computed value (short circuiting), meaning it "properly" relies
> on (>>=). liftM2 (<|>) - or rather liftA2 (<|>) - does not, it doesn't unbox
> anything, so it cannot possibly be correct.

That's what I meant by "I think 'm' has to be a monad", sorry if I wasn't clear!

I admit I'm weak on Alternative, and haven't really found many uses
for it, other than the parser combinator thing, so the conversation
was interesting anyway.  Come to think of it I've used (<|>) for
choice and mzero for failure in parsers, so that's really confusing,
why one of each?  Perhaps because parsec predates Applicative and
Alternative.

I'm also not too clear on the uses of MonadPlus, aside from being the
pure version of my 'try' function, or the relation between Alternative
and MonadPlus.  There was some discussion recently with the whole AMP
thing that implied that it's a historical relic of Applicative coming
after Monad, but then some implication that maybe it's not.  I guess
you'd need a MonadPlus if choice relied on the value inside, but
presumably if there's an Alternative, then MonadPlus should have the
same implementation.


More information about the Haskell-Cafe mailing list