State monad
A state monad represents stateful computation as a function from an input state to a result paired with an output state, enabling composable state transitions.
Functional Design and Architecture: Examples in Haskell
A state monad is a monadic abstraction that threads changeable state through computations while presenting state transitions as composable values.
- How it is used
- Organizes immutable application state as monadic context, avoiding repetitive explicit model threading in stateful scripts.
- How deep it goes
- Explains get, put, bind-based state threading, runners, and StateT stacks, while deliberately deferring category theory.
- Examples
- Uses Age updates, a Minesweeper board, state-stack tests, and spaceship rotation control scripts.
- What you can do after
- Apply it via State and StateT to structure, run, and test pure stateful computations with layered effects.
Read how Functional Design and Architecture: Examples in Haskell explains state monad →
Functional Programming in Scala, Second Edition
A state monad represents a stateful computation as a function from an input state to a result paired with an output state.
- How it is used
- Represents stateful computations as composable values instead of directly mutating shared state.
- How deep it goes
- Defines unit, flatMap, get, and set, then demonstrates state threading; exercises defer laws and combinator behavior.
- Examples
- Uses zipWithIndex to number list elements by incrementing an Int state through a for-comprehension.
- What you can do after
- Build it from scratch by implementing State, unit, flatMap, get, set, and state-threading programs.
Read how Functional Programming in Scala, Second Edition explains state monad →
Related concepts
- monadkind of · A monad is a functional abstraction that encapsulates computational context and provides operations for composing computations while preserving that context.
- state-passingimplements · State-passing is a technique in which state is supplied as a function argument and the resulting computation returns updated state.
- runStateused by · runState is a Haskell state-monad function that executes a stateful computation from an initial state and returns its result together with the final state.
- monad stackpart of · A monad stack is a nested composition of monads or monad transformers that combines multiple computational effects behind one monadic interface.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

