Author : Joe Fredette License : BSD3 Copyright : Joe Fredette
Maintainer : Joe Fredette jfredett.at.gmail.dot.com Stability : Unstable Portability : portable
- class (Eq s, Eq i, Show s, Show i) => Card s i where
- type Cards s i = [CardT s i]
- class Parse a where
- 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 whereSource
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?
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.
mkDeck :: (Bounded s, Bounded i, Enum s, Enum i, Card s i) => Deck s iSource
Creates a deck, used as in: `mkDeck::your 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
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`
A type to separate Hands from Decks.
module Data.HCard.Instances