move :: Board -> Direction -> Board
move board direction = board {selector = (fst (selector board) fst direction, snd (selector board) snd direction)}
這是我寫的代碼,但是當我嘗試使用“移動”時收到此錯誤訊息:
<interactive>:91:1: error:
* No instance for (Show Board) arising from a use of `print'
* In a stmt of an interactive GHCi command: print it`
我知道我無法列印“initBoard”,但我看不出我在這里做錯了什么。
uj5u.com熱心網友回復:
在 GHCi 中,如果您這樣做:
ghci> board1 = move board0 dir
您將能夠毫無錯誤地使用您的move功能。但是,如果您評估型別不是 的實體的運算式Show,則會出現錯誤:
ghci> move board0 dir
任何其他型別也是如此,例如函式:
ghci> add1 = (1 )
ghci> add1 2
3
ghci> add1
<interactive>:5:1: error:
? No instance for (Show (Integer -> Integer))
arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
? In a stmt of an interactive GHCi command: print it
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/517122.html
標籤:哈斯克尔
