MonadPlus versus Alternative

Hey everyone, What is the difference between MonadPlus and Alternative? In my mind, it would make sense for the difference to be that the former provides "and" semantics (i.e., x `mplus` y means do both x and y) whereas the latter provides "or" semantics (i.e., x <|> y means do x or y but not both). However, when I look at the instances defined for List I see that it is exactly the same as MonadPlus. So is there any difference between the interpretation of MonadPlus and Alternative, or is the only difference between them that the former applies to Monad whereas the latter applies to Applicative? Also, along similar lines, why does MonadPlus exist when it is essentially just a special case of Monoid? (That is, any MonadPlus instance could be equivalently cast as a Monoid instance.) Thanks! Greg

MonadPlus is `or` semantics, as is Alternative. It does, indeed, reflect
the Applicative/Monad difference.
On Sat, Oct 29, 2011 at 8:02 PM, Gregory Crosswhite
Hey everyone,
What is the difference between MonadPlus and Alternative? In my mind, it would make sense for the difference to be that the former provides "and" semantics (i.e., x `mplus` y means do both x and y) whereas the latter provides "or" semantics (i.e., x <|> y means do x or y but not both). However, when I look at the instances defined for List I see that it is exactly the same as MonadPlus.
So is there any difference between the interpretation of MonadPlus and Alternative, or is the only difference between them that the former applies to Monad whereas the latter applies to Applicative?
Also, along similar lines, why does MonadPlus exist when it is essentially just a special case of Monoid? (That is, any MonadPlus instance could be equivalently cast as a Monoid instance.)
Thanks! Greg
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, Oct 30, 2011 at 04:02, Gregory Crosswhite wrote:
So is there any difference between the interpretation of MonadPlus and Alternative, or is the only difference between them that the former applies to Monad whereas the latter applies to Applicative?
Somewhat OT, but this led me to playing with ConstraintKinds: https://github.com/spl/sandbox/blob/master/ConstraintKindsAlternativeMonadPl... Regards, Sean

On 10/29/11 11:02 PM, Gregory Crosswhite wrote:
Hey everyone,
What is the difference between MonadPlus and Alternative? In my mind, it would make sense for the difference to be that the former provides "and" semantics (i.e., x `mplus` y means do both x and y) whereas the latter provides "or" semantics (i.e., x<|> y means do x or y but not both). However, when I look at the instances defined for List I see that it is exactly the same as MonadPlus.
As other's've mentioned, they both have "or" semantics and it's just an artifact of the Monad/Applicative split. However, an additional note. For lists or sets, the mplus/(<|>) functions could be interpreted as both "and" and "or" semantics, depending on what you think lists are. If you think of them as a collection of multiple answers, then concatenating/unioning is colloquially regarded as saying I have xs and ys. However, if you think of them as giving a non-deterministic answer, then the concatenation/union should be regarded as saying you can chose the xs or the ys, which is closer to the logical interpretation of union as disjunction. I guess my point is that the notion of "and" isn't especially well-defined. At the very least there are three different notions of "and". We have the andThen notion which corresponds to monadic bind, probabilistic conjunction, and Sigma types. We have the andAlso notion which corresponds to unions conceived of as nondeterminisms, also covers the linear conjunction which only lets you take one of the projections, and is the one involved with the idea of "and"ing two functions with (+++). And we have the bothAnd notion which corresponds to Cartesian products, logical conjunction, the linear conjunction which lets you take both projections, and the notion of "and"ing two functions with (***). -- Live well, ~wren
participants (4)
-
David Barbour
-
Gregory Crosswhite
-
Sean Leather
-
wren ng thornton