<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi,</div><div><br></div><div>Thanks all for your good help. &nbsp; I was caught up in sequential thinking about monads so much so that I treated the lambda expressions as separate functions rather than a nested big one.&nbsp;</div><div><br></div><div>That clears up a lot of nagging doubts.&nbsp;</div><div><br></div><div>Cheers,</div><div><br></div><div>Matt.&nbsp;</div><div><br>On 20 Jul 2013, at 00:18, Rogan Creswick &lt;<a href="mailto:creswick@gmail.com">creswick@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">On Fri, Jul 19, 2013 at 3:58 PM, Matt Ford <span dir="ltr">&lt;<a href="mailto:matt@dancingfrog.co.uk" target="_blank">matt@dancingfrog.co.uk</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto"><div>Hi,</div><div><br></div><div>Thanks for the help.</div>

<div><br></div><div>I thought &gt;&gt;= was left associative? &nbsp;It seems to be in the examples from Learn You A Haskell.</div><div><br></div><div>I tried to use the associative law to bracket from the right but it didn't like that either...</div>

<div><span><br></span></div><div><span>[1,2] &gt;&gt;= (\x -&gt; (\n -&gt; [3,4])) x &nbsp;&gt;&gt;= \m -&gt; return (n,m))</span></div></div></blockquote><div><br></div><div>I think the issue is that you need to first take into account the lambdas *then* use what you know about the properties of (&gt;&gt;=).</div>

<div><br></div><div>I found this stackoverflow answer helpful (<a href="http://stackoverflow.com/a/11237469">http://stackoverflow.com/a/11237469</a>)</div><div><br></div><div>"The rule for lambdas is pretty simple: the body of the lambda extends as far to the right as possible without hitting an unbalanced parenthesis."</div>

<div><br></div><div>&nbsp;So, the first lambda runs to the end of the expression:</div><div><br></div><div>[1,2] &gt;&gt;= (\n -&gt; [3,4] &gt;&gt;= \m -&gt; return (n,m))<br></div><div><br></div><div>Now, there is still a lambda nested inside the first lambda: \m -&gt; return (n,m)</div>

<div><br></div><div><div>[1,2] &gt;&gt;= (\n -&gt; [3,4] &gt;&gt;= (\m -&gt; return (n,m)))</div></div><div><br></div><div>You violated the implied grouping that these new parentheses make explicit when you tried to apply the associative law above.</div>

<div><br></div><div>Timon's post continues from this point to show the full deconstruction.</div><div><br></div><div>--Rogan</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="auto"><div><br></div><div><span>Any thoughts?</span></div><span class=""><font color="#888888"><div><br></div><div>Matt&nbsp;</div></font></span><div><div class="h5"><div><br></div><div>On 19 Jul 2013, at 23:35, Rogan Creswick &lt;<a href="mailto:creswick@gmail.com" target="_blank">creswick@gmail.com</a>&gt; wrote:<br>

<br></div><blockquote type="cite"><div><div dir="ltr">On Fri, Jul 19, 2013 at 3:23 PM, Matt Ford <span dir="ltr">&lt;<a href="mailto:matt@dancingfrog.co.uk" target="_blank">matt@dancingfrog.co.uk</a>&gt;</span> wrote:<div>

<div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I started by putting brackets in<br>
<br>
([1,2] &gt;&gt;= \n -&gt; [3,4]) &gt;&gt;= \m -&gt; return (n,m)<br>
<br>
This immediately fails when evaluated: I expect it's something to do<br>
with the n value now not being seen by the final return.<br></blockquote><div><br></div><div>You're bracketing from the wrong end, which your intuition about n's visibility hints at. &nbsp;Try this as your first set of parens:</div>



<div><br></div><div>&nbsp;[1,2] &gt;&gt;= (\n -&gt; [3,4] &gt;&gt;= \m -&gt; return (n,m))<br></div><div><br></div><div>--Rogan</div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<br>
It seems to me that the return function is doing something more than<br>
it's definition (return x = [x]).<br>
<br>
If ignore the error introduced by the brackets I have and continue to<br>
simplify I get.<br>
<br>
[3,4,3,4] &gt;&gt;= \m -&gt; return (n,m)<br>
<br>
Now this obviously won't work as there is no 'n' value. &nbsp;So what's<br>
happening here? Return seems to be doing way more work than lifting the<br>
result to a list, how does Haskell know to do this? &nbsp;Why's it not in the<br>
function definition? &nbsp;Are lists somehow a special case?<br>
<br>
Any pointers appreciated.<br>
<br>
Cheers,<br>
<span><font color="#888888"><br>
--<br>
Matt<br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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></div></div></div>
</div></blockquote></div></div></div></blockquote></div><br></div></div>
</div></blockquote></body></html>