The desugaring is simpler with the current setup:<br><br>do { e }<br> => e<br>do { let p = e; STMTS } <br> => let p = e in (do { STMTS })<br>do { e; STMTS }<br> => e >> (do { STMTS })<br>do { p <- e; STMTS }<br>
=> e >>= \x -> case x of { p -> (do { STMTS }) ; _ -> fail "pattern match failure" }<br> [x is a fresh variable]<br><br>My guess is that >> is infixl because<br> (1) m >>= f >>= g should make sense<br>
(2) >> should match fixity and precedence with >>=<br><br><div class="gmail_quote">On Tue, Feb 14, 2012 at 9:50 PM, Michael Baikov <span dir="ltr"><<a href="mailto:manpacket@gmail.com">manpacket@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Most docs ([1], [2]) about do-notation syntactic sugar tends to<br>
describe following expressions as equivalent:<br>
<br>
"do { a; b; c }" and "a >> b >> c", but they are not: first one gets<br>
de-sugared into "a >> (b >> c)", second one is equivalent to "(a >><br>
b) >> c", because (>>) is declared using infixl.<br>
<br>
This should not be a problem, monadic law of Associativity states that<br>
"(m >>= f) >>= g ≡ m >>= (\x -> f x >>= g)", but this leads to<br>
generating different Core output and may lead to different performance<br>
(and it does, do { Just 4 ; Just 4 ... } is about 2% faster than Just<br>
4 >> Just 4 >> ... if compiled with -O0, but 13% slower when compiled<br>
with -O11)<br>
<br>
This also leads to lots of fun when your monad breaks Associativity law :)<br>
<br>
Is there any reasons except for those 13% speed gain for this?<br>
<br>
[1]: <a href="http://en.wikibooks.org/wiki/Haskell/do_Notation" target="_blank">http://en.wikibooks.org/wiki/Haskell/do_Notation</a><br>
[2]: <a href="http://book.realworldhaskell.org/read/monads.html#monads.dot" target="_blank">http://book.realworldhaskell.org/read/monads.html#monads.dot</a><br>
<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>