我有以下数据类型:
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]
有没有办法让我
Rank
肯定的
Card
在列表中加一?例如,给出一个列表
[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 =
我被卡住了。有人能帮我吗?非常感谢。