Claus Reinke wrote:
 mplus' :: MonadPlus m => Maybe a -> m a -> m a
 mplus' m l = maybeToMonad m `mplus` l

 maybeToMonad :: Monad m => Maybe a -> m a
 maybeToMonad = maybe (fail "Nothing") return

In general, however, this operation can't be done.  For example,
how would you write:

 mplus' :: IO a -> [a] -> [a]

Perhaps the question should be: is there an interesting structure
that would allow us to capture when this kind of merging Monads
is possible?

For me, it seems that Foldable is the other side of Alternative. A functor F supports Alternative if (F a) supports a monoidal structure for the construction of values, and it supports Foldable if (F a) supports a monoidal structure for the decomposition of values. That means that we can give a translation from every Foldable functor to every Alternative functor as follows:

  foldable2alternative = foldr (<|>) empty . fmap pure

Tillmann
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to