0
我發現這部分在http://www.haskell.org/haskellwiki/State_Monad 但我不清楚我將如何定義c和f的初始狀態。如何定義State Monad中的初始狀態?
雖然它與IORefs一起工作,但我不需要全局可變數據。
increment :: StateT Integer IO Integer
increment = do
n <- get
put (n+1)
return n
plusOne :: Integer -> IO Integer
plusOne n = execStateT increment n
printTChan mtch = do
forever $ do
m <- atomically $ readTChan mtch
case m of
"ping" -> plusOne c
_ -> plusOne f
print (c)
你看過'runState'嗎? – Ingo 2012-02-29 22:47:51