module Data.Currency.Amounts
(
Amount(..)
, toUSD
, fromUSD
, convert
, compareAmounts
, module Data.Currency.Currencies
) where
import Data.Currency.Currencies
data Amount c = Amount c Double deriving (Show, Read, Eq)
instance (Currency c) => Ord (Amount c) where
(Amount _ v1) <= (Amount _ v2) = v1 <= v2
toUSD :: (Currency c) => Amount c -> Amount USD
toUSD (Amount c amount) = Amount USD $ amount * exchangeUSD c
fromUSD :: (Currency c) => c -> Amount USD -> Amount c
fromUSD c (Amount USD amount) = Amount c $ amount / exchangeUSD c
convert :: (Currency c', Currency c) => c' -> Amount c -> Amount c'
convert c' amount = fromUSD c' $ toUSD amount
compareAmounts :: (Currency c1, Currency c2) => Amount c1 -> Amount c2 -> Ordering
compareAmounts a1 a2 = compare (toUSD a1) (toUSD a2)