Skip to content

Instantly share code, notes, and snippets.

@danclien
Last active August 29, 2015 13:57
Show Gist options
  • Save danclien/9906414 to your computer and use it in GitHub Desktop.
Save danclien/9906414 to your computer and use it in GitHub Desktop.
import Control.Monad.State
type App = StateT String IO
main :: IO ()
main = do
x <- runStateT code ""
print x -- ("stateResult","stateValue")
return ()
code :: App String
code = do
writeState
x <- readState
liftIO $ print x -- "stateResult"
return x
writeState :: App ()
writeState = put "stateValue"
readState :: App String
readState = do
x <- get
liftIO $ print x -- "stateValue"
return "stateResult"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment