Subscribed unsubscribe Subscribe Subscribe

StateT

Haskell
import Control.Monad.State

tick :: State Int Int
tick = modify (+1) >> get

tickT :: StateT Int IO Int
tickT = modify (+1) >> get >>= liftIO . print >> get

main :: IO ()
main = do
  print $ runState (tick >> tick >> tick) 0
  runStateT (tickT >> tickT >> tickT) 0 >>= print
*Main> :main
(3,3)
1
2
3
(3,3)