StateT is a Haskell monad transformer that adds readable and updatable state to computations in an underlying monad. StateT s m a records the state type, underlying monad, and computation result. section 15.1.2
Use the core operations to manage state during a computation:
- get retrieves the current state. section 15.1.2
- put replaces the current state with a supplied value. section 15.1.2
- modify applies a function to the existing state. section 15.1.2
- liftIO performs IO inside StateT while preserving the threaded state. section 15.1.2
Counting directories during recursive traversal
Define type App a = StateT Int IO a, perform filesystem operations with liftIO, increment the counter with modify, and run the computation using execStateT (example "foo") 0. A richer application state can track recursion depth and transferred files with a Stats record, helper modification functions, and a Monoid identity for an empty state. section 15.1.2

