Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
evalMoneyIn :: (Conversion -> Maybe Rate) -> MoneyExpr -> Currency -> Maybe Money
evalMoneyIn findRate expr refCurrency = visit expr
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