4 ms·
> `ma` must be evaluated before `mb` No - either one can be evaluated first, with the other being short-circuited. If you swap the order of those lines, the fu
by truculent 4y ago
> `ma` must be evaluated before `mb`
No - either one can be evaluated first, with the other being short-circuited. If you swap the order of those lines, the function is exactly the same (in terms of inputs and outputs, at least).
- solomonb 4y agoThis `do` syntax desugars to binds like: ma >>= \a -> mb >>= \b -> return (a > b) We can then inline the definition of `>>=` and `return` to get: case ma of Nothing -> Nothing Just a -> case mb of Nothing -> Nothing Just b -> Just (a > b) Imagine that `mb` is actually a really expensive computation that we don't want to perform unless `ma` returns a value. Sequencing our case statements in this way allows us to do that. `mb` will remain an unevaluated thunk until `ma` evaluates to a `Just a` value.