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