IT lexicon › Programming › do-notation

do-notation

Programming På svenska → Updated: 2026-05-28

Haskell syntactic sugar for chained bind calls. Make monadic code look imperative. do { x <- getName; y <- getAge; return (x, y) } equivalent to getName >>= \x -> getAge >>= \y -> return (x, y).

Modern equivalents: JavaScript async/await (do-notation for the Promise monad), Rust ? (Result/Option-monad version), Python asyncio.run (similar spirit). Scala has for-comprehension. Use cases: chain IO actions, error handling, list comprehensions. Mental model: do-notation makes monadic code readable for humans without forcing imperative thinking. Haskell's strength: the same syntax works for ANY monad (IO, Maybe, Either, State, Reader, Writer, custom). Modern Python/JS: async/await is a special case for one specific monad.

← Back to the lexicon