【发布时间】:2012-10-06 17:05:12
【问题描述】:
我目前正在为学校作业制作国际象棋游戏,并且我的棋子已定义
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 , 骑士 = 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)
我收到以下错误(我也尝试了很多,但根据此链接,我似乎非常接近 Something somewhat similar
Couldn't match expected type `Piece' with actual type `(t0, t1)'
感谢任何帮助 亲切的问候,我
【问题讨论】:
-
应该是
show (Piece piecetype color)而不是show (piecetype,color)。 -
我的一些错误,它就像一个魅力,感谢 Satvik
标签: haskell types instance show