Skip to content

Instantly share code, notes, and snippets.

@tokiwoousaka
Last active August 29, 2015 14:10
Show Gist options
  • Save tokiwoousaka/7c7fd14dca71a5da0e2e to your computer and use it in GitHub Desktop.
Save tokiwoousaka/7c7fd14dca71a5da0e2e to your computer and use it in GitHub Desktop.
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