Created
December 1, 2013 21:47
-
-
Save bananu7/7741265 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| f :: State Int Int | |
| f = do | |
| x <- get | |
| let x' = x+1 | |
| put x' | |
| return 0 | |
| g :: State Int Int | |
| g = do | |
| modify (+1) | |
| return 0 | |
| op :: Int -> IO () | |
| op i = print i | |
| wrap :: (Int -> IO ()) -> StateT Int IO () | |
| wrap f = do | |
| i <- get | |
| liftIO $ f i | |
| loop = do | |
| modify (+1) | |
| return () | |
| run n = do | |
| runStateT (replicateM_ n ((wrap op) >> loop)) 0 | |
| main = run 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment