Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Values = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace deriving (Show)
- data Suits = Spades | Hearts | Diamonds | Clubs deriving (Show)
- type Cards = (Suits, Values)
- {- greaterCard
- Compares the values of two playing cards and establishes which has the greatest value
- PRE: Values = [2, ..., 14]
- RETURNS: Card with the greatest value
- EXAMPLES: greaterCard (Spades Ace) (Spades King) = True
- greaterCard (Hearts King) (Spades King) = False
- -}
- greaterCard :: Cards -> Cards -> Bool
- greaterCard (suits1, value1) (suits2, value2)
- | convertValue value1 > convertValue value2 = True
- | convertValue value1 == convertValue value2 = if convertSuits suits1 > convertSuits suits2 then True else False
- | otherwise = False
- {- convertValue
- -}
- convertValue :: Values -> Int
- convertValue Two = 2
- convertValue Three = 3
- convertValue Four = 4
- convertValue Five = 5
- convertValue Six = 6
- convertValue Seven = 7
- convertValue Eight = 8
- convertValue Nine = 9
- convertValue Ten = 10
- convertValue Jack = 11
- convertValue Queen = 12
- convertValue King = 13
- convertValue Ace = 14
- {- convertSuits
- -}
- convertSuits :: Suits -> Int
- convertSuits Spades = 4
- convertSuits Hearts = 3
- convertSuits Diamonds = 2
- convertSuits Clubs = 1
- (+?) :: Maybe Int -> Maybe Int -> Maybe Int
- _ +? Nothing = Nothing
- Nothing +? _ = Nothing
- Just x +? Just y = Just (x+y)
- (-?) :: Maybe Int -> Maybe Int -> Maybe Int
- _ -? Nothing = Nothing
- Nothing -? _ = Nothing
- Just x -? Just y = Just (x-y)
- (*?) :: Maybe Int -> Maybe Int -> Maybe Int
- _ *? Nothing = Nothing
- Nothing *? _ = Nothing
- Just x *? Just y = Just (x * y)
- (/?) :: Maybe Int -> Maybe Int -> Maybe Int
- _ /? Nothing = Nothing
- Nothing /? _ = Nothing
- Just x /? Just y
- | y == 0 = Nothing
- | otherwise Just (div x y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement