On Sun, May 3, 2009 at 4:41 AM, Luke Palmer <[email protected]> wrote:

> 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]


Silly me:

maybeToList (Just 1) `mplus` [2,3,4] ==> [1,2,3,4]



>
>
> Which may not be what you want...
>
> Luke
>
> On Sat, May 2, 2009 at 9:26 PM, michael rice <[email protected]> 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` [] ==> [1]
>>
>> If not, can someone supply a simple example of combining computations?
>>
>> Michael
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to