Advertisement
Guest User

Untitled

a guest
Sep 19th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data CurrencyType = GBP | USD | EUR
  2.   deriving (Show)
  3.  
  4. data Currency = Currency CurrencyType Int
  5.   deriving (Show)
  6.  
  7. gt :: MonadError String m => Currency -> Currency -> m Bool
  8. gt (Currency k1 v1) (Currency k2 v2)
  9.   | k1 == k2 = pure $ v1 > v2
  10.   | otherwise = throwError "Cannot compute 'gt' on different currency kinds"
  11.  
  12. add :: MonadError String m => Currency -> Currency -> m Currency
  13. add (Currency k1 v1) (Currency k2 v2)
  14.   | k1 == k2 = pure $ Currency k1 (v1 + v2)
  15.   | otherwise = throwError "Cannot compute 'add' on different currency kinds"
  16.  
  17. subtract :: MonadError String m => Currency -> Currency -> m Currency
  18. subtract (Currency k1 v1) (Currency k2 v2)
  19.   | k1 == k2 = pure $ Currency k1 (v1 - v2)
  20.   | otherwise = throwError "Cannot compute 'subtract' on different currency kinds"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement