Looking at the State Monad's wiki, I'm trying to understand the runState and put functions.
As I understand runState, it takes a first argument of State, which has a "universe", s, and a value, a. It takes a second argument of a universe. Finally, it returns a (a, s) where a is the new value and s is the new universe?
ghci> :t runState
runState :: State s a -> s -> (a, s)
Example:
ghci> let s = return "X" :: State Int String
ghci> runState s 100
("X",100)
However, I'm don't understand the put result:
ghci> runState (put 5) 1
((),5)
Since runState returns an (a, s), why is the a of type ()?
I'm not confident on my above attempted explanations. Please correct me, and answer my question on put.
When using
putwith theStatemonad, it has the types -> State s ().putsets the state to its argument, and that's all it does. As for its return value: it's essentially a dummy value, because there's nothing useful to return.This is also evident in its definition
put s = state $ \ _ -> ((), s).