我目前正在为学校作业制作国际象棋游戏,并且我的棋子已定义
data Piece = Piece { piecetype :: PieceType, color :: PieceColor }
data PieceType = Pawn | Knight | Bishop | Rook | Queen | King
data PieceColor = Black | White deriving Eq
现在我必须将一块打印为单个字符(king = k,queen = q,knight = n 等)对于黑色块,该值是其白色值的大写(king = K,queen = Q,knight = N等)所以我做了三个show实例
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)
我收到以下错误(我也尝试了很多比这更多的但根据这个链接我看起来很接近的东西有点相似
Couldn't match expected type `Piece' with actual type `(t0, t1)'
我感谢任何帮助亲切的问候,我