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

Safe HaskellNone
LanguageHaskell98

Data.HCard

Description

Author : Joe Fredette License : BSD3 Copyright : Joe Fredette

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

Synopsis

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?

Minimal complete definition

suit, index, construct

Associated Types

data CardT s i :: * Source

Methods

suit :: CardT s i -> s Source

index :: CardT s i -> i Source

construct :: i -> s -> CardT s i Source

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

Instances

type Cards s i = [CardT s i] Source

class Parse a where Source

Parse is just a read instance with read exposed as the MRD. For most types, this will just be Read, but when dealing w/ index types, it can be a pain to parse numbers via read and end up with the expected format of "index-suit"

Methods

parse :: String -> a Source

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 i Source

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 i Source

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)