Skip to content

Instantly share code, notes, and snippets.

@saevarb
Created August 4, 2015 20:41
Show Gist options
  • Save saevarb/5271254022dcadb0d929 to your computer and use it in GitHub Desktop.
Save saevarb/5271254022dcadb0d929 to your computer and use it in GitHub Desktop.
import Control.Monad.State
foo :: StateT Int IO ()
foo = do
get >>= \s -> liftIO . putStrLn $ "state = " ++ show s
iterateState
liftIO . putStr $ "Please enter q to quit> "
c <- liftIO getLine
unless (c == "q") foo
where
iterateState = do
modify (+1)
main :: IO ()
main = do
let initialState = 3
evalStateT foo initialState
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment