Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 given in the link.

How to do it…

  1. Import the following packages:

    import qualified Numeric.Probability.Distribution as Dist
    import Numeric.Probability.Distribution ((??))
    import Control.Monad.Trans.State (StateT(StateT, runStateT), evalStateT)
    import...