我有以下數據類型:有沒有辦法在Haskell的列表中加一個Enum Bounded Ord類型?
data Suit = Club | Diamond | Heart | Spade
deriving (Eq, Ord, Bounded, Enum)
data Rank =
R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 |
Jack | Queen | King | Ace
deriving (Eq, Ord, Bounded, Enum)
data Card = Card {suit::Suit, rank::Rank}
deriving (Eq, Bounded)
,現在有[Card]
列表。有沒有辦法讓我在列表中加一個Card
的Rank
?例如給出一個清單[Card Club R2, Card Club R2]
我想使它[Card Club R3, Card Club R3]
。我寫了下面的代碼:
-- | Update certain number of cards' rank in the list.
updateRankList :: Int -> [Card] -> [Card]
updateRankList num (x : xs)
| num == 0 = []
| otherwise = updateRank x ++ updateRankList (num - 1) xs
-- | Update a card's rank, didn't finish.
updateRank :: Card -> Card
updateRank card =
而我卡住了。誰能幫我?謝謝。
一如既往,請想想邊界條件,並更新你的問題。 – 2014-09-11 13:12:32
對不起,我不太清楚您的邊界條件是什麼意思。 – user3928256 2014-09-11 13:21:48
「Ace」的'plus'級別是什麼?它應該環繞到「R2」嗎? – Lee 2014-09-11 13:22:48