這是國家單子代碼我試圖找出「實例顯示狀態」沒有編譯
data State a = State (Int -> (a, Int))
instance Monad State where
return x = State (\c -> (x, c))
State m >>= f = State (\c ->
case m c of { (a, acount) ->
case f a of State b -> b acount})
getState = State (\c -> (c, c))
putState count = State (\_ -> ((), count))
instance Show State where -- doesn't work
show (State a) = show a -- doesn't work
我努力使國家作爲展會的實例,這樣我可以看到的動作在ghci提示符上輸入getState
和putState count
。
任何教程或鏈接到狀態Monad材料也不錯。
如果您遇到想要解決的編譯器錯誤,則應始終將其置於該問題中。 – sth