Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data CurrencyType = GBP | USD | EUR
- deriving (Show)
- data Currency = Currency CurrencyType Int
- deriving (Show)
- gt :: MonadError String m => Currency -> Currency -> m Bool
- gt (Currency k1 v1) (Currency k2 v2)
- | k1 == k2 = pure $ v1 > v2
- | otherwise = throwError "Cannot compute 'gt' on different currency kinds"
- add :: MonadError String m => Currency -> Currency -> m Currency
- add (Currency k1 v1) (Currency k2 v2)
- | k1 == k2 = pure $ Currency k1 (v1 + v2)
- | otherwise = throwError "Cannot compute 'add' on different currency kinds"
- subtract :: MonadError String m => Currency -> Currency -> m Currency
- subtract (Currency k1 v1) (Currency k2 v2)
- | k1 == k2 = pure $ Currency k1 (v1 - v2)
- | otherwise = throwError "Cannot compute 'subtract' on different currency kinds"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement