[Haskell-cafe] Problems with nested Monads

Job Vranish jvranish at gmail.com
Fri Jul 10 11:34:13 EDT 2009

I'm trying to make a function that uses another monadic function inside a
preexisting monad, and I'm having trouble.
Basically my problem boils down to this. I have three monadic functions with
the following types:
f :: A -> M B
g :: B -> N C
h :: C -> M D
(M and N are in the monad class)
I want a function i where
i :: A -> M (N D)

the best I can come up with is:
i :: A -> M (N (M D))
i a = liftM (liftM h) =<< (return . g) (f a)

I'm starting to feel pretty sure that what I'm going for is impossible. Is
this the case?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090710/80f98fe4/attachment.html

More information about the Haskell-Cafe mailing list