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