Statefulness means that an application's behavior depends on information retained across operations or interactions. Functional programming does not eliminate state; it organizes state and side effects so they do not spread unpredictably through the code. section 7.0 section 7.3
A stateful design separates business logic from state-handling mechanisms. Pure logic can use immutable state passed as arguments, while an interpreter or application layer can manage mutable operational state and connect the system's layers. section 7.1.1 section 7.3
Common ways to represent and control state include:
- Argument-passing state represents each transition with an immutable state value. section 7.3
- State monads hide argument passing behind a composable monadic context, allowing state to be updated during a computation. section 7.3
- Mutable mechanisms such as IORefs, MVars, vectors, and STM can improve convenience or performance when their access is carefully controlled. section 7.3
- Concurrent state benefits from suitable granularity: independently mutable values avoid repeatedly replacing a whole shared map. section 8.2.2
Layered sandwich application
A recipe describes business behavior through an eDSL, an interpreter consumes ingredients and updates operational state, and the application layer assembles the ingredients, interpreter, and output. The recipe remains separate from the mutable state mechanism. section 7.1.1
Figure 8.8 Data structure with two layers of concurrent mutability
Inspect the two-layer concurrent structure in which an outer map locates independently mutable values, illustrating fine-grained state updates. section 8.2.2













