Last active
August 29, 2015 14:00
-
-
Save munro/11308178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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