我目前正在一盤棋的作業和我的作品被定義哈斯克爾 - 顯示實例的多個數據類型
data Piece = Piece { piecetype :: PieceType, color :: PieceColor }
data PieceType = Pawn | Knight | Bishop | Rook | Queen | King
data PieceColor = Black | White deriving Eq
現在我要打印件作爲單個字符(王= K,女王= q,knight = n等)黑色棋子的值是其白色值的大小(king = K,queen = Q,knight = N等) 所以我做了三個顯示實例
instance Show PieceColor where
show Black = "B"
show White = "W"
instance Show PieceType where
show Pawn = "P"
show Knight = "N"
show Bishop = "B"
show Rook = "R"
show Queen = "Q"
show King = "K"
第三個問題是
instance Show Piece where
show (piecetype, color) = show piecetype
if show color == "W"
then show piecetype
else toUpper (show piecetype)
我收到以下錯誤(我也嘗試過比這多很多,但是根據這個鏈接,我似乎相當接近Something somewhat similar
Couldn't match expected type `Piece' with actual type `(t0, t1)'
我感謝所有幫助 親切的問候,我
它應該是'show(piece piecetype color)'而不是'show(piecetype,color)'。 – Satvik
在我的一端有一些錯誤,它的作品就像一個魅力,謝謝Satvik – M4st3rM1nd