Skip to content

Instantly share code, notes, and snippets.

@wwkeyboard
Created February 4, 2014 12:28
Show Gist options
  • Save wwkeyboard/8802736 to your computer and use it in GitHub Desktop.
Save wwkeyboard/8802736 to your computer and use it in GitHub Desktop.
Trying to model playing cards in Haskell(not sure this is right)
-- | Main entry point to the application.
module Main where
data Suit = Hearts | Dimonds | Clubs | Spades
data Rank = A | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | J | Q | K
data Card = Card Rank Suit
rankWord :: Rank -> String
rankWord A = "Ace"
rankWord R2 = "Two"
rankWord R3 = "Three"
rankWord R4 = "Four"
rankWord R5 = "Five"
rankWord R6 = "Six"
rankWord R7 = "Seven"
rankWord R8 = "Eight"
rankWord R9 = "Nine"
rankWord R10 = "Ten"
rankWord J = "Jack"
rankWord Q = "Queen"
rankWord K = "King"
suitWord :: Suit -> String
suitWord Hearts = "Hearts"
suitWord Dimonds = "Dimonds"
suitWord Clubs = "Clubs"
suitWord Spades = "Spades"
cardWord :: Card -> String
cardWord (Card r s) = do
let rank = rankWord r
suit = suitWord s
rank ++ " of " ++ suit
-- | The main entry point.
main :: IO ()
main = do
let card = Card A Spades
word = cardWord card
putStrLn word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment