Last active
August 29, 2015 14:10
-
-
Save tokiwoousaka/7c7fd14dca71a5da0e2e 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 | |
main :: IO () | |
main = print $ runState f 1000 --状態の初期値を1000にしてfを実行 | |
f :: State Int () | |
f = do | |
x <- sub1 | |
sub2 x | |
--状態から値を取り出して10足して返す | |
sub1 :: State Int Int | |
sub1 = do | |
x <- get | |
return $ x + 10 | |
--引数を2倍して状態に代入 | |
sub2 :: Int -> State Int () | |
sub2 a = do | |
x <- return 2 | |
put $ a * x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment