It might be helpful to fully replace the &gt;&gt;= operators with their definitions:<br><br>m1 &gt;&gt;= \x1 -&gt; m2 &gt;&gt;= \x2 -&gt; return (f x1 x2)<br>foldr ((++) . (\x1 -&gt; m2 &gt;&gt;= \x2 -&gt; return (f x1 x2))) [] m1<br>
foldr ((++) . (\x1 -&gt; foldr ((++) . (\x2 -&gt; return (f x1 x2))) [] m2)) [] m1<br>foldr ((++) . (\x1 -&gt; foldr ((++) . (\x2 -&gt; [f x1 x2])) [] m2)) [] m1<br><br>which in your example yields:<br><br>foldr ((++) . (\x1 -&gt; foldr ((++) . (\x2 -&gt; [x1 + x2])) [] [3,4])) [] [1,2]<br>
<br>Does that make a bit more sense?<br><br clear="all">-R. Kyle Murphy<br>--<br>Curiosity was framed, Ignorance killed the cat.<br>
<br><br><div class="gmail_quote">On Fri, Feb 24, 2012 at 11:42,  <span dir="ltr">&lt;<a href="mailto:franco00@gmx.com">franco00@gmx.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span style="font-family:Verdana"><span style="font-size:12px"><div> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">I am a bit puzzled by liftM2. I know what it does, but let&#39;s take a look at<br> 
                the implementation.</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">liftM2  :: (Monad m) =&gt; (a1 -&gt; a2 -&gt; r) -&gt; m a1 -&gt; m a2 -&gt; m r<br> 
                liftM2 f m1 m2          = do { x1 &lt;- m1; x2 &lt;- m2; return (f x1 x2) }</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">Which could be rewritten (I am a bit uncomfortable with the do notation):</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">m1               &gt;&gt;= \x1 -&gt;<br> 
                m2               &gt;&gt;= \x2 -&gt;<br> 
                return (f x1 x2)</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">so: liftM2 (+) [1,2] [3,4] = [4,5,5,6]</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">The instance of the List monad tells me that:</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">instance  Monad []  where<br> 
                    m &gt;&gt;= k   = foldr ((++) . k) [] m<br> 
                    m &gt;&gt; k    = foldr ((++) . (\ _ -&gt; k)) [] m<br> 
                    return x  = [x]<br> 
                    fail _    = []</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">That foldr is just doing a concatMap, it seems to me.<br> 
                But I still don&#39;t get the | return (f x1 x2) | part.<br> 
                The first thing I thought was:</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">return ( (+) [1,2] [3,4] )</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">but of course this is not the IO monad, the bind operator does not just<br> 
                fetch stuff from outer space.<br> 
                 <br> 
                What is there really &#39;inside&#39; x1 and x2 when the return statement is<br> 
                evaluated, though?</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">I think I intuitively got it (x1 and x2 are bound to m1 and m2, every<br> 
                f x1 x2 expression is evaluated and then put together in a list), but<br> 
                it would be helpful to see what really happens to interiorise it.</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">I started from the first step</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">(&gt;&gt;=) m1 = foldr. ((++) . k) [] m1 -- partially applying m1</span></span></p> 
        <p style="margin:0px;padding:0px"> 
                <span style="font-family:Verdana"><span style="font-size:12px">but cannot really proceed from there. Any help will be appreciated,<br> 
                if you think the question is not clear enough, do not hesitate to ask.</span></span></p> 
</div> 
</span></span>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>