This document discusses state monads in Haskell. It defines the State monad and its operators (>>=) and return. It shows how state is threaded through computations using these operators. It provides examples of using the state monad to increment a counter and to define functions like put and get that set and get the current state. In summary:
1) It introduces the State monad and its operators for threading state through computations.
2) It gives examples like incrementing a counter to demonstrate how the state is transformed and passed between function applications in the monad.
3) It shows how functions like put and get can be defined to set and access the internal state using the monad operators.
9. (>>=)
(State x) >>= f = State $ s -> let (v,s') = x s in runState (f v) s'
State(s0 ) (v(s0), s(s0))
...
(v, s') = (s0 × 2, s0) s = (s × 2, s)
f v = f (s × 2) = (s × 2 + s0, s0 + 1)
(f v) s' = (s × 2 + s0, s0 + 1) s = (s × 2 + s, s + 1)
(s0 × 2, s0) >>= f = (s0 × 2 + s0, s0 + 1)
10. Int >>= State Int Int ∋ (s0 × 2, s0)
(=<<) f
f
Int State Int Int ∋(s0 × 2 + s0, s0 + 1)