これは私が理解しようとしている州のモナドコードです
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
を確認できるように、StateをShowのインスタンスとして作成しようとしています。putState count
チュートリアルやStateMonadの資料へのリンクもいいでしょう。