money-0.1.0: Money

Data.Money

Description

Synopsis

# Money

newtype Money currency Source #

Money in a currency.

Examples:

>>> 1000 :: Money COP
COP 1000.0
>>> 1000 :: Money EUR
EUR 1000.0
>>> 1000 :: Money USD
USD 1000.0
>>> 999.99 :: Money USD
USD 999.99
>>> 1000 + 500 :: Money COP
COP 1500.0
>>> (1000 :: Money COP) + (500 :: Money EUR)
...
>>> 1000 == (500 * 2 :: Money USD)
True
>>> 1000 < (500 :: Money EUR)
False

Constructors

 Money FieldsgetAmount :: Rational

Instances

 Eq (Money currency) Source # Methods(==) :: Money currency -> Money currency -> Bool #(/=) :: Money currency -> Money currency -> Bool # Fractional (Money currency) Source # Methods(/) :: Money currency -> Money currency -> Money currency #recip :: Money currency -> Money currency #fromRational :: Rational -> Money currency # Num (Money currency) Source # Methods(+) :: Money currency -> Money currency -> Money currency #(-) :: Money currency -> Money currency -> Money currency #(*) :: Money currency -> Money currency -> Money currency #negate :: Money currency -> Money currency #abs :: Money currency -> Money currency #signum :: Money currency -> Money currency #fromInteger :: Integer -> Money currency # Ord (Money currency) Source # Methodscompare :: Money currency -> Money currency -> Ordering #(<) :: Money currency -> Money currency -> Bool #(<=) :: Money currency -> Money currency -> Bool #(>) :: Money currency -> Money currency -> Bool #(>=) :: Money currency -> Money currency -> Bool #max :: Money currency -> Money currency -> Money currency #min :: Money currency -> Money currency -> Money currency # Source # Show money in USD. MethodsshowList :: [Money USD] -> ShowS # Source # Show money in EUR. MethodsshowList :: [Money EUR] -> ShowS # Source # Show money in COP. MethodsshowList :: [Money COP] -> ShowS #

# 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 COP
COP 3167.2
>>> 1.06 :: ExchangeRate EUR USD
USD 1.06
>>> 0.94 :: ExchangeRate USD EUR
EUR 0.94

Constructors

 ExchangeRate FieldsgetExchangeRate :: Money currency2

Instances

 Eq (ExchangeRate currency1 currency2) Source # Methods(==) :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 -> Bool #(/=) :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 -> Bool # Fractional (ExchangeRate currency1 currency2) Source # Methods(/) :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #recip :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #fromRational :: Rational -> ExchangeRate currency1 currency2 # Num (ExchangeRate currency1 currency2) Source # Methods(+) :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #(-) :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #(*) :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #negate :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #abs :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #signum :: ExchangeRate currency1 currency2 -> ExchangeRate currency1 currency2 #fromInteger :: Integer -> ExchangeRate currency1 currency2 # Show (Money cur2) => Show (ExchangeRate cur1 cur2) Source # MethodsshowsPrec :: Int -> ExchangeRate cur1 cur2 -> ShowS #show :: ExchangeRate cur1 cur2 -> String #showList :: [ExchangeRate cur1 cur2] -> ShowS #

# 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 1000
COP 3182010.0
>>> convert (interchange usdToCop) 1000
USD 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 1000
USD 0.31...
>>> convert' (interchange usdToCop) 1000
COP 3182010.0
>>> convert' usdToCop (convert' (interchange usdToCop) 1000)
USD 1000.0
>>> convert' usdToCop (convert usdToCop 1000)
USD 1000.0