Yes, I had always desired that the operator &gt;&gt;= should have been right associative for this short cut even when written without the &#39;do&#39; notation.<br><br><div class="gmail_quote">On Tue, May 13, 2008 at 3:39 AM, John Hamilton &lt;<a href="mailto:jlhamilton@gmail.com">jlhamilton@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I&#39;m trying to understand how short circuiting works with the Maybe monad.<br>
Take the expression n &gt;&gt;= f &gt;&gt;= g &gt;&gt;= h, which can be written as<br>
(((n &gt;&gt;= f) &gt;&gt;= g) &gt;&gt;= h) because &gt;&gt;= is left associative. &nbsp;If n is<br>
Nothing, this implies that (n &gt;&gt;= f) is Nothing, and so on, each nested<br>
sub-expression easily evaluating to Nothing, but without there being a<br>
quick way to short circuit at the beginning.<br>
<br>
Now take the example<br>
<br>
 &nbsp; do x &lt;- xs<br>
 &nbsp; &nbsp; &nbsp;y &lt;- ys<br>
 &nbsp; &nbsp; &nbsp;z &lt;- zs<br>
 &nbsp; &nbsp; &nbsp;return (x, y, z)<br>
<br>
which I believe desugars like<br>
<br>
 &nbsp; &nbsp;xs &gt;&gt;= (\x -&gt; ys &gt;&gt;= (\y -&gt; zs &gt;&gt;= (\z -&gt; return (x, y, z))))<br>
<br>
Here the associativity of &gt;&gt;= no longer matters, and if xs is Nothing the<br>
whole expression can quickly be determined to be Nothing, because Nothing<br>
&gt;&gt;= _ = Nothing. &nbsp;Am I looking at this correctly?<br>
<br>
- John<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>
</blockquote></div><br>