导出代数数据类型的显示

时间:2012-03-11 15:48:37

标签: haskell types

我有以下类型:

data Suit = Club | Diamond | Heart | Spade deriving Show
data Rank = R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | Jack | Queen | King | Ace deriving Show
data JokerColor = Red | Black deriving Show
data JCard = NormalCard Suit Rank | JokerCard JokerColor

如何展示JCard?目前我得到No instance for (Show JCard)

1 个答案:

答案 0 :(得分:10)

以与JCard相同的方式导出JokerColor的节目。

data JokerColor = Red | Black deriving Show
data JCard = NormalCard Suit Rank | JokerCard JokerColor deriving Show

对于大多数类型,人们通常派生Eq,Ord和Show。