haskell-issues
haskell-issues copied to clipboard
transformers: Add modifyT and getsT
These rectangles deserve to be completed:
execState :: State s () -> (s -> s) modify :: (s -> s) -> State s ()
execStateT :: StateT s m () -> (s -> m s) modifyT :: (s -> m s) -> StateT s m ()
evalState :: State s a -> (s -> a) gets :: (s -> a) -> State s a
evalStateT :: StateT s m a -> (s -> m a) getsT :: (s -> m a) -> StateT s m a
The implementations would be something like:
modifyT f = StateT $ \s -> ((),) <$> f s
getsT f = StateT $ \s -> (,s) <$> f s
Could you elaborate on how they are useful here? (I looked thru the #haskell archives, but having a coherent example here would be better.)
I use them pretty often, lots for example on http://lpaste.net/148381 (You might find some more on https://www.google.de/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:lpaste.net+modifyT ).
Have you ever used StateT as a function? The use cases are similar, and the rectangle runState-state-runStateT-StateT is equivalent to the above.