[Haskell-cafe] Problems with nested Monads

Miguel Mitrofanov miguelimo38 at yandex.ru
Fri Jul 10 18:49:23 EDT 2009


You can do this if D -> M (N D) is a monad itself.

I suggest you study monad transformers - may be it's what you really  
want.

On 10 Jul 2009, at 19:34, Job Vranish wrote:

> 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?  
> _______________________________________________
> 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