Because put
has a side effect. It sticks something into the state monad that can be accessed and modified later.
It's return value is just ()
which is boring, so we don't care about it, but we certainly want to make sure we put the new random generator into the state.
Think of it like this, the state monad is really a function s -> (a, s)
. and put
is
put s = \oldState -> (() , s)
So this has a side effect, it's throwing away the old state and replacing it. Consider this example
test = put 1 >> get >>= \x -> put 2 >> get >>= \y -> return (x, y)
-- or with do notation
test' = do
put 1
x <- get
put 2
y <- get
return (x, y)
Here x
is 1
and y
is 2
. Clearly put has interesting effects beyond just it's return value.