Created
August 14, 2017 16:03
-
-
Save deque-blog/fed5c7def19a4c75908d37377a8b8e31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
evalMoneyIn :: (Conversion -> Maybe Rate) -> MoneyExpr -> Currency -> Maybe Money | |
evalMoneyIn findRate expr refCurrency = visit expr | |
where | |
visit (KnownAmount (Money amt curr)) = do | |
rate <- findRate (curr, refCurrency) | |
pure $ Money (rate * amt) refCurrency | |
visit (MoneyAdd subs) = do | |
ms <- mapM visit subs | |
pure $ Money (sum (map amount ms)) refCurrency | |
visit (MoneyMul expr factor) = do | |
m <- visit expr | |
pure $ Money (factor * amount m) refCurrency |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment