Skip to content

Comment on Pedagogical Downsides of Haskellparent

Comments

This `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.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.