{-# LANGUAGE TemplateHaskell #-} import Control.Monad import Control.Monad.Trans import Control.Monad.State import Control.Monad.State.Puts import Data.Setters data Record = Record { count :: Int, flag :: Bool } deriving (Eq, Show) $(declareSetters ''Record) testState :: StateT Record IO () testState = do cnt <- gets count puts setCount (cnt + 1) puts setFlag (odd cnt) liftIO $ print cnt main = do runStateT (replicateM 10 testState) (Record 0 False) return ()