[Haskell-cafe] Combining computations

Tony Morris tonymorris at gmail.com
Sun May 3 03:59:04 EDT 2009


michael rice wrote:
> If you look at this stuff long enough it almost begins to make sense.
> Maybe. ;-)
>
> I've been messing around with MonadPlus and I understand its usage
> with the Maybe and List monads. Since one use of Monads is combining
> computations, how can I combine a Maybe with a List?
>
> let m1 = Nothing
> let m2 = [1]
> let m3 = m1 `mplus` m2  ==> [1]    --if the Maybe is Nothing, do nothing 
>
> let m1 = Just 1
> let m2 = []
> let m3 = m1 `mplus` m2  ==> [1]  --if the Maybe is not Nothing, add it
> to the list
>
> Or am I misunderstanding combining computations?
>
> Michael
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>   

Hi Michael,
You'll want the Data.Maybe.listToMaybe and Data.Maybe.maybeToList functions.

-- 
Tony Morris
http://tmorris.net/




More information about the Haskell-Cafe mailing list