[Haskell-cafe] Combining computations
lrpalmer at gmail.com
Sun May 3 06:41:20 EDT 2009
mplus requires both arguments to be in the same monad (the same type,
even). Fortunately, the empty list behaves like Nothing, and a singleton
list behaves like Just. So convert the Maybe before composing, using:
maybeToList Nothing = 
maybeToList (Just x) = [x]
(The maybeToList function can be found in Data.Maybe)
Keep in mind that this will give you:
Just 1 `mplus` [2,3,4] ==> [1,2,3,4]
Which may not be what you want...
On Sat, May 2, 2009 at 9:26 PM, michael rice <nowgate at yahoo.com> wrote:
> I posted something similar about an hour ago but it seems to have gotten
> lost. Very strange.
> I've read that Monads can combine computations. Can a Maybe monad be
> combined with a List monad such that
> Nothing `mplus`  ==> 
> Just 1 `mplus`  ==> 
> If not, can someone supply a simple example of combining computations?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe