modify
has type
modify :: (MonadState s m) => (s -> s) -> m ()
The first argument is a plain s -> s
function which modifies the state. So, while you are on the right track by trying to use const
, you don't have to put the state in a tuple:
put s = modify $ const s
Note that, while you can define put
in terms of modify
, that means you won't be able to give a general definition of modify
; rather, you have to do it for each concrete monad which is an instance of MonadState
. That explains why, in Control.Monad.State
, get
and put
are class methods of MonadState
: how you implement them depends on the specific state monad. modify
, then, is defined in terms of get
and put
.