0
錯誤的單子井字遊戲,我開始在Haskell實現井字遊戲:在Haskell
import Control.Monad.State
data Player = X | O
data Field = Player | I deriving (Eq, Show, Read)
data GameField = G [[Field]]
type GameState = State GameField()
initGame :: GameState
initGame = do
put $ G [[I,I,I],[I,I,I],[I,I,I]]
action = do
initGame
test = execState action $ G [[I,I,I],[I,I,I],[I,I,I]]
當我執行「測試」我收到以下錯誤:
No instance for (Show GameField) arising from a use of `print'
Possible fix: add an instance declaration for (Show GameField)
In a stmt of an interactive GHCi command: print it
這是什麼問題的原因,我該如何解決它?
對於加「派生秀」您GameField decleration ..這將簡單地加以解決記錄:大多數情況下,當GHC抱怨丟失的實例時,這實際上不是問題。 – leftaroundabout