[Haskell-cafe] Short circuiting and the Maybe monad
dave at zednenem.com
Tue May 13 16:28:01 EDT 2008
2008/5/13 Abhay Parvate <abhay.parvate at gmail.com>:
> Yes, I had always desired that the operator >>= should have been right
> associative for this short cut even when written without the 'do' notation.
You pretty much always want "a >>= b >>= c" to parse as "(a >>= b) >>=
c" and not "a >>= (b >>= c)". In the latter case, the two uses of
(>>=) aren't in the same monad.
You can get desired effect with the Kleisli composition operator
(>=>), which is in recent versions of Control.Monad. Unfortunately, it
has the same precedence as (>>=), so you can't use them together
Using it, "a >>= b >>= c" can be rewritten "a >>= (b >=> c)" which is
short for "a >>= \x -> b x >>= c".
Dave Menendez <dave at zednenem.com>
More information about the Haskell-Cafe