[Haskell-cafe] MonadPlus versus Alternative

wren ng thornton wren at freegeek.org
Mon Oct 31 01:39:04 CET 2011

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,

More information about the Haskell-Cafe mailing list