A monad sequences computations whose results carry a context, such as a Maybe value that can be present or absent. It becomes useful when the result of one step determines whether or how the next step runs. Applicatives combine independent wrapped computations; monads handle dependent ones. section 3.2 section 3.2.2
In Haskell, bind (>>=) takes a wrapped value and a function that accepts an unwrapped value but returns another wrapped value. It produces a result in the same context, rather than leaving nested wrappers. The return function wraps an ordinary result: for example, a safe division function can return Nothing for a zero denominator and a wrapped quotient otherwise. section 3.2.5 section 3.2.3
Chain a Maybe calculation
If plusOne takes an Int and returns a Maybe Int, Just 42 >>= plusOne produces Just 43. The function can create a wrapped result without requiring the caller to unwrap and rewrap the input. section 3.2.5
withMonad :: Int -> String -> Maybe String withMonad age name = do validateAge age return (greet name)
The do-notation listing shows age validation before a greeting. If validation yields Nothing, the computation stops; otherwise, return wraps the greeting in Maybe. The line-by-line form expresses the same dependency as bind. section 3.2.5
Monads are a tool for composition, not just for Maybe: they preserve context while chaining steps that depend on earlier results. Haskell also uses monads to sequence I/O, though that application is only noted here. section 3.3








