Yes, I had always desired that the operator >>= should have been right associative for this short cut even when written without the 'do' notation.<br><br><div class="gmail_quote">On Tue, May 13, 2008 at 3:39 AM, John Hamilton <<a href="mailto:jlhamilton@gmail.com">jlhamilton@gmail.com</a>> 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'm trying to understand how short circuiting works with the Maybe monad.<br>
Take the expression n >>= f >>= g >>= h, which can be written as<br>
(((n >>= f) >>= g) >>= h) because >>= is left associative. If n is<br>
Nothing, this implies that (n >>= 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>
do x <- xs<br>
y <- ys<br>
z <- zs<br>
return (x, y, z)<br>
<br>
which I believe desugars like<br>
<br>
xs >>= (\x -> ys >>= (\y -> zs >>= (\z -> return (x, y, z))))<br>
<br>
Here the associativity of >>= no longer matters, and if xs is Nothing the<br>
whole expression can quickly be determined to be Nothing, because Nothing<br>
>>= _ = Nothing. 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>