| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Money
Description
- module Data.Money.Currency
- newtype Money currency = Money {}
- newtype ExchangeRate currency1 currency2 = ExchangeRate {
- getExchangeRate :: Money currency2
- interchange :: ExchangeRate cur1 cur2 -> ExchangeRate cur2 cur1
- convert :: ExchangeRate cur1 cur2 -> Money cur1 -> Money cur2
- convert' :: ExchangeRate cur2 cur1 -> Money cur1 -> Money cur2
Currencies
module Data.Money.Currency
Money
newtype Money currency Source #
Money in a currency.
Examples:
>>>1000 :: Money COPCOP 1000.0
>>>1000 :: Money EUREUR 1000.0
>>>1000 :: Money USDUSD 1000.0
>>>999.99 :: Money USDUSD 999.99
>>>1000 + 500 :: Money COPCOP 1500.0
>>>(1000 :: Money COP) + (500 :: Money EUR)...
>>>1000 == (500 * 2 :: Money USD)True
>>>1000 < (500 :: Money EUR)False
Exchange rates
newtype ExchangeRate currency1 currency2 Source #
An exchange rate, that is, the value of one currency for the purpose of conversion to another.
Examples:
>>>3167.20 :: ExchangeRate USD COPCOP 3167.2
>>>1.06 :: ExchangeRate EUR USDUSD 1.06
>>>0.94 :: ExchangeRate USD EUREUR 0.94
Constructors
| ExchangeRate | |
Fields
| |
Instances
| Eq (ExchangeRate currency1 currency2) Source # | |
| Fractional (ExchangeRate currency1 currency2) Source # | |
| Num (ExchangeRate currency1 currency2) Source # | |
| Show (Money cur2) => Show (ExchangeRate cur1 cur2) Source # | |
Interchanges
interchange :: ExchangeRate cur1 cur2 -> ExchangeRate cur2 cur1 Source #
Interchange (or flip) an exchange rate.
Examples:
>>>interchange (1.06 :: ExchangeRate EUR USD)EUR 0.94...
>>>interchange (0.94 :: ExchangeRate USD EUR)USD 1.06...
>>>interchange (interchange (1.06 :: ExchangeRate EUR USD))USD 1.06
>>>interchange (interchange (0.94 :: ExchangeRate USD EUR))EUR 0.94
Conversions
convert :: ExchangeRate cur1 cur2 -> Money cur1 -> Money cur2 Source #
Convert money using an exchange rate.
Examples:
>>>usdToCop = 3182.01 :: ExchangeRate USD COP
>>>convert usdToCop 1000COP 3182010.0
>>>convert (interchange usdToCop) 1000USD 0.31...
>>>convert (interchange usdToCop) (convert usdToCop 1000)USD 1000.0
convert' :: ExchangeRate cur2 cur1 -> Money cur1 -> Money cur2 Source #
Convert money using an interchanged (or flipped) exchange rate.
Examples:
>>>usdToCop = 3182.01 :: ExchangeRate USD COP
>>>convert' usdToCop 1000USD 0.31...
>>>convert' (interchange usdToCop) 1000COP 3182010.0
>>>convert' usdToCop (convert' (interchange usdToCop) 1000)USD 1000.0
>>>convert' usdToCop (convert usdToCop 1000)USD 1000.0