2012-03-11 68 views
0

我有以下幾種類型:推導查看代數數據類型

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)

回答

10

只需按照JokerColor的方法推導出JCard

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

對於大多數類型,人們通常派生Eq,Ord和Show。

+1

謝謝!我以前得到無關的錯誤,並認爲這個語法是不正確的... – 2012-03-11 15:56:16