m1 >> m2
== m1 >>= (\_->m2)
== state $
\s ->
let
(iObj, newSt) = (runState m1) s
g = runState ( (\_->m2) iObj )
in
g newSt
== state $
\s ->
let
newSt = snd ( (runState m1) s )
g = runState m2
in
g newSt
= state $
\s ->
(runState m2) (snd (runState m1 s))
Substituting m for m1 and get for m2 causes
m >> get to reduce to
state $
\s -> (\st->(st,st)) (snd (runState m s))
In short
m >> get
is
state $
\s -> (snd (runState m s), snd (runState m s))
which tells us the >> operator works on the
state even as it ignores the interior object.
Here is the put function for replacing the state.
put :: s -> State s ()
put newState = state $ \s -> ((),newState)