Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Cards where
- data Suit = Hearts
- |Diamonds
- |Spades
- |Clubs
- deriving (Eq, Enum)
- dumbLookup :: (Eq a) => a -> [(a, b)] -> b
- dumbLookup _ [] = error "derp"
- dumbLookup z ((x,y):xs) | x == z = y
- | otherwise = dumbLookup z xs
- instance Show Suit = dumbLookup x [(Hearts, "H"), (Diamonds, "D"), (Spades, "S"), (Clubs, "C")]
- data Rank = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace
- deriving (Eq, Ord, Enum)
- instance Show Rank = -- see above, same trick but different values
- data Card = Card {rank :: Rank, suit :: Suit}
- instance Show Card where show card = show (rank card) ++ show (suit card)
- instance Ord Card where compare card1 card2 = compare (rank card1) (rank card2)
- instance Eq Card where card1 == card2 = rank card1 == rank card2
Add Comment
Please, Sign In to add comment