Creating a data structure for playing cards

Many probability and statistic problems are posed using playing cards. In this recipe, we will create a data structure and useful functions for the cards.

There are a total of 52 playing cards in a standard deck. Each card has one of the following four suits:

  • Spades
  • Hearts
  • Diamonds
  • Clubs

Also, each card has one out of 13 ranks as follows:

  • Integers between 2 and 10 inclusive
  • Jack
  • Queen
  • King
  • Ace

Getting ready

Install the probability library using cabal as follows:

$ cabal install probability

Review the sample code on the probability package about collections at http://hackage.haskell.org/package/probability-0.2.4/docs/src/Numeric-Probability-Example-Collection.html.

The recipe is based heavily on the probability example ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.