
I'm trying to understand how short circuiting works with the Maybe monad. Take the expression n >>= f >>= g >>= h, which can be written as (((n >>= f) >>= g) >>= h) because >>= is left associative. If n is Nothing, this implies that (n >>= f) is Nothing, and so on, each nested sub-expression easily evaluating to Nothing, but without there being a quick way to short circuit at the beginning. Now take the example do x <- xs y <- ys z <- zs return (x, y, z) which I believe desugars like xs >>= (\x -> ys >>= (\y -> zs >>= (\z -> return (x, y, z)))) Here the associativity of >>= no longer matters, and if xs is Nothing the whole expression can quickly be determined to be Nothing, because Nothing
= _ = Nothing. Am I looking at this correctly?
- John