<div>The problem you have is that monad composition isn&#39;t defined in general. You would need some form of distributive law either for your monads in general, or for your particular monads wrapped around this particular kind of value.</div>

<div> </div>
<div>What I would look for is a function of the form of one of:</div>
<div> </div>
<div>distribute :: N (M a) -&gt; M (N a)</div>
<div>joinInner :: M (N (M a)) -&gt; M (N a)</div>
<div>joinOuter :: N (M (N a)) -&gt; M (N a)<br><br>that holds for your partiular monads M and N.</div>
<div> </div>
<div>IIRC Mark P. Jones wrote a paper or a lib back around &#39;93 that used these forms of distributive laws to derive monads from the composition of a monad and a pointed endofunctor.</div>
<div> </div>
<div>-Edward Kmett</div>
<div> </div>
<div class="gmail_quote">On Fri, Jul 10, 2009 at 11:34 AM, Job Vranish <span dir="ltr">&lt;<a href="mailto:jvranish@gmail.com">jvranish@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">I&#39;m trying to make a function that uses another monadic function inside a preexisting monad, and I&#39;m having trouble.<br>
Basically my problem boils down to this. I have three monadic functions with the following types:<br>f :: A -&gt; M B<br>g :: B -&gt; N C<br>h :: C -&gt; M D<br>(M and N are in the monad class)<br>I want a function i where <br>
i :: A -&gt; M (N D)<br><br>the best I can come up with is:<br>i :: A -&gt; M (N (M D))<br>i a = liftM (liftM h) =&lt;&lt; (return . g) (f a)<br><br>I&#39;m starting to feel pretty sure that what I&#39;m going for is impossible. Is this the case? <br>
_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>