The Maybe and Either monads have nothing to do with state, for example.
See this is what I'm talking about. What does `state` mean to you where monads don't have any relation? It's just an abstract structure—what makes something state or not is the context.
State can be modeled as a monad, but monads aren't a synonym for state. Just like squares are technically rectangles, but "rectangle" isn't a synonym for "square."
Comments
See this is what I'm talking about. What does `state` mean to you where monads don't have any relation? It's just an abstract structure—what makes something state or not is the context.
State can be modeled as a monad, but monads aren't a synonym for state. Just like squares are technically rectangles, but "rectangle" isn't a synonym for "square."
How do I think of the State monad?
- Like a Mealy machine: https://en.wikipedia.org/wiki/Mealy_machine
- Like a pure way to compose functions that use a nameless, global mutable variable.
- As a newtype wrapper over the type "s -> (a, s)" where s is the type of the state and a is the type of the computation.