A memoized state monad parameterized by a representable functor
g, where the representatation of
g,
Rep g
is the state to carry.
The
return function leaves the state unchanged, while
>>= uses the final state of the first computation as
the initial state of the second.