Chapter 12. Stateful programs and stateful computations
This chapter covers
- What makes a program stateful?
- Writing stateful programs without mutating state
- Generating random structures
- Composing stateful computations
Since chapter 1, I’ve been preaching against state mutation as a side effect that should be avoided at almost any cost, and you’ve seen several examples of refactoring programs to avoid state mutation. In this chapter you’ll see how the functional approach works when there’s a requirement for the program to be stateful.
But what’s a stateful program exactly? It’s a program whose behavior differs, depending on past inputs or events. By analogy, if somebody says “Good morning,” you’ll probably mindlessly greet them in return. ...