Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Money (s :: Nat)
- mkMoney :: KnownNat s => Date -> Currency -> Quantity s -> Money s
- mkMoneyFromScientific :: KnownNat s => Date -> Currency -> Scientific -> Money s
- moneyDate :: KnownNat s => Money s -> Maybe Date
- moneyCurrency :: KnownNat s => Money s -> Maybe Currency
- moneyQuantity :: KnownNat s => Money s -> Maybe (Quantity s)
- convert :: (KnownNat s, KnownNat k) => Money s -> Currency -> Quantity k -> Money s
- convertWithQuote :: (KnownNat s, KnownNat k) => Money s -> FXQuote k -> Money s
Documentation
data Money (s :: Nat) Source #
Instances
Eq (Money s) Source # | |
Ord (Money s) Source # | |
KnownNat s => Show (Money s) Source # | |
KnownNat s => ToJSON (Money s) Source # |
|
Defined in Haspara.Internal.Money | |
KnownNat s => FromJSON (Money s) Source # |
|
mkMoneyFromScientific :: KnownNat s => Date -> Currency -> Scientific -> Money s Source #
convert :: (KnownNat s, KnownNat k) => Money s -> Currency -> Quantity k -> Money s Source #
Converts the given Money
value to another given currency with the given
rate.
>>>
import Haspara
>>>
let eur = either error id $ currency "EUR"
>>>
let usd = either error id $ currency "USD"
>>>
let date = read "2021-01-01" :: Date
>>>
let eurmoney = mkMoney date eur (quantity 0.42 :: Quantity 2) :: Money 2
>>>
convert eurmoney eur (quantity 1 :: Quantity 4)
MoneySome 2021-01-01 EUR 0.42>>>
convert eurmoney usd (quantity 1 :: Quantity 4)
MoneySome 2021-01-01 USD 0.42>>>
convert eurmoney usd (quantity 1.1516 :: Quantity 4)
MoneySome 2021-01-01 USD 0.48