Skip to content

Instantly share code, notes, and snippets.

@munro
Last active August 29, 2015 14:00
Show Gist options
  • Save munro/11308178 to your computer and use it in GitHub Desktop.
Save munro/11308178 to your computer and use it in GitHub Desktop.
import Control.Monad.State
import Control.Monad.Trans
type StackState a = StateT [Integer] IO a
--type StackStateIO = StateT [Integer] IO ()
push :: Integer -> StackState ()
push a = do
modify (a:)
return ()
pop :: StackState Integer
pop = do
item <- get
modify (drop 1)
return (head item)
crazyCombinedMonad :: StackState Integer
crazyCombinedMonad = do
value <- pop
liftIO (putStrLn ("popped value " ++ (show value)))
return (123 :: Integer)
main :: IO ()
main = do
value <- runStateT (crazyCombinedMonad) [6,4,3]
putStrLn $ show $ value
-- Output:
-- popped value 6
-- (123,[4,3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment