[Haskell-cafe] not possible with monad transformers ?
Mike Gunter
m at ryangunter.com
Mon Nov 29 17:53:41 EST 2004
This:
foo a b = do
output "before"
let r = liftM2 (+) a b
when (r == Nothing) $ output "error"
return r -- ??? "lift r"
seems to address your complains, but I don't understand what you want
well enough to know if this is that.
mike
Pavel Zolnikov <pavelzolnikov at yahoo.com> writes:
> Hi, I have been playing with Maybe and Output monad transformers
> and realized that I cannot make the following work nicely:
>
>> foo a b = do
>> output "before"
>> r <- (liftM2(+)) a b
>> when r == Nothing $ output "error"
>> return r
>
> As soon as computation produces Nothing, I am loosing ability to do any
> output. I think what I need is not wrapping one monad into another with
> transformer; I need some sort of monad combiner:
>
>> newtype MC m1 m2 = MC (m1 a, m2 b)
>
> So I could execute both of monads âin parallelâ. But I have no idea
> how to express this or even if this is doable at all. Any comments?
>
> Thanks,
> Pavel.
>
> P.S. Here is summary of what I tried with transformers so far:
>
> Letâs say I have following monad transformers:
>
>> newtype MaybeMonadT m a = MMT (m a)
>
>> newtype OuptutMonadT m o a = OMT (m a, o)
>
> And I am trying to use following monads:
>
>> type M1 a = MaybeMonadT OutputM a
>> type M2 a = OuptutMonadT Maybe String a
>
> Now, they both wonât quite work in the following example:
>
>> foo a b = do
>> output "before"
>> r <- (liftM2(+)) a b
>> when r == Nothing $ output "error"
>> return r
>
>
> In case of M1, as soon as I get Nothing in r, computation will stop
> and return without any output gathered.
>
> In case of M2, as soon as I get Nothing in r, computation will stop
> and return only with output gathered so far. That is
>> output "error"
> will never be called.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list