HCard-0.0: A library for implementing a Deck of Cards

Safe Haskell | None

Data.HCard

Description

Author : Joe Fredette License : BSD3 Copyright : Joe Fredette

Maintainer : Joe Fredette jfredett.at.gmail.dot.com Stability : Unstable Portability : portable

Synopsis

- class (Eq s, Eq i, Show s, Show i) => Card s i where
  - data CardT s i :: *
  - suit :: CardT s i -> s
  - index :: CardT s i -> i
  - construct :: i -> s -> CardT s i
  - (@@) :: i -> s -> CardT s i
- type Cards s i = [CardT s i]
- class Parse a where
  - parse :: String -> a
- newtype Deck s i = Deck (Cards s i)
- type DeckST s i = State (Deck s i)
- mkDeck :: (Bounded s, Bounded i, Enum s, Enum i, Card s i) => Deck s i
- shuffleDeck :: (Card s i, RandomGen g) => Deck s i -> g -> Deck s i
- shuffleDeckIO :: Card s i => Deck s i -> IO (Deck s i)
- dealHands :: Card s i => Int -> Int -> DeckST s i [Hand s i]
- dealHand :: Card s i => Int -> DeckST s i (Hand s i)
- newtype Hand s i = Hand (Cards s i)
- module Data.HCard.Instances

# Documentation

class (Eq s, Eq i, Show s, Show i) => Card s i where Source

The Main class, this is -- effectively -- a type-indexed record. Specifically, it requires two types, one representing the suit, the other representing the index/rank. The suit, index, and construct functions are generic forms of the record accessors.

The bulk of the implementation takes place in generic type instances, supporting equality irrelevant of ordering, ordering, parsing from a normal form (index-suit) and enum/bounded

TODO: Write deriving instance?

Associated Types

data CardT s i :: *Source

Methods

suit :: CardT s i -> sSource

index :: CardT s i -> iSource

construct :: i -> s -> CardT s iSource

(@@) :: i -> s -> CardT s iSource

Instances

Card Suit Index |

type Cards s i = [CardT s i]Source

class Parse a where Source

Methods

parse :: String -> aSource

Instances

Parse Index |
Parse Suit |
(Parse s, Parse i, Card s i) => Parse (CardT s i) |
(Parse s, Parse i, Card s i) => Parse (Hand s i) |

newtype Deck s i Source

Separate Deck from Hand, even though the types are isomorphic, we don't want shuffling to be to liberal.

TODO: Make Deck clever enough to support reshuffling when the deck runs out -- it should store cards it has already seen till it runs out of the main deck, reshuffle, redeal.

Constructors

Deck (Cards s i) |

Instances

Card s i => Eq (Deck s i) |
Card s i => Show (Deck s i) |
(Arbitrary s, Arbitrary i, Card s i) => Arbitrary (Deck s i) |

type DeckST s i = State (Deck s i)Source

Type wrapper for stateful decks, useful for sorting

mkDeck :: (Bounded s, Bounded i, Enum s, Enum i, Card s i) => Deck s iSource

Creates a deck, used as in: `mkDeck::deck type here`, or w/ inference.

shuffleDeck :: (Card s i, RandomGen g) => Deck s i -> g -> Deck s iSource

Shuffles a deck given a generator

shuffleDeckIO :: Card s i => Deck s i -> IO (Deck s i)Source

Shuffles using the standard generator

dealHands :: Card s i => Int -> Int -> DeckST s i [Hand s i]Source

Deals `n` hands of `qty` cards, written in the state monad.

dealHand :: Card s i => Int -> DeckST s i (Hand s i)Source

Helper for dealHands, also somewhat useful, equiv. to `dealHands 1 qty`

newtype Hand s i Source

A type to separate Hands from Decks.

Constructors

Hand (Cards s i) |

Instances

Card s i => Eq (Hand s i) |
Card s i => Show (Hand s i) |
(Parse s, Parse i, Card s i) => Parse (Hand s i) |

module Data.HCard.Instances