Skip to content

Instantly share code, notes, and snippets.

@jpfuentes2
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpfuentes2/bb16edfdb923d155bc69 to your computer and use it in GitHub Desktop.
Save jpfuentes2/bb16edfdb923d155bc69 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveDataTypeable #-}
import Control.Monad.Random
import System.Random.Shuffle
import Data.Typeable
import Data.Data
import Control.Applicative
data Suit = Hearts | Clubs | Diamonds | Spades
deriving (Eq, Data, Typeable)
data Value
= Ace
| King
| Queen
| Jack
| Two
| Three
| Four
| Five
| Six
| Seven
| Eight
| Nine
| Ten
deriving (Eq, Enum, Bounded, Data, Typeable)
data Card = Card Suit Value
type Deck = [Card]
instance Show Card where
show (Card s v) = (show $ toConstr s) ++ ":" ++ (show $ toConstr v)
deck :: Deck
deck = Card <$> [Hearts, Clubs, Diamonds, Spades] <*> [Ace ..Ten]
main = do
deck <- evalRandIO $ shuffleM $ concat $ replicate 1 deck
print deck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment