我正在尝试编写一个函数,从所有可以选择的卡片中随机选择一张卡片。这些卡是我声明为等级的类型。我的代码如下所示:
data Rank = Ace | Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten
| Jack | Queen | King
deriving(Eq, Ord, Bounded, Enum, Show, Read)
pickCard :: Rank
pickCard = error "How should I pick a random card here? :("
当然我希望这个函数做的是从列表中选择一个随机值[Ace .. King]
我该怎么做?请记住,我是 Haskell 和函数式编程的初学者。