Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Simple currency handling and exchange library
- data USD = USD
- data RUB = RUB
- data EUR = EUR
- data BTC = BTC
- data LTC = LTC
- class (Typeable a, Eq a) => CurrencySymbol a
- class ScalableAdditive a where
- data ExchangeRates
- makeExchangeRates :: (CurrencySymbol a, CurrencySymbol b) => [((a, b), Double)] -> ExchangeRates
- data Money a
- makeMoney :: CurrencySymbol a => Double -> a -> Money a
- makeUSD :: Double -> Money USD
- makeRUB :: Double -> Money RUB
- makeEUR :: Double -> Money EUR
- makeBTC :: Double -> Money BTC
- makeLTC :: Double -> Money LTC
- amount :: Money a -> Double
- symbol :: Money a -> a
- findRate :: (CurrencySymbol a, CurrencySymbol b) => ExchangeRates -> a -> b -> Maybe Double
- exchangeTo :: (CurrencySymbol a, CurrencySymbol b) => ExchangeRates -> Money a -> b -> Maybe (Money b)
- sampleRates :: ExchangeRates
Documentation
U.S. Dollar
class (Typeable a, Eq a) => CurrencySymbol a Source #
Things that can be looked up in the rates dictionary
CurrencySymbol LTC Source # | |
CurrencySymbol BTC Source # | |
CurrencySymbol EUR Source # | |
CurrencySymbol RUB Source # | |
CurrencySymbol USD Source # | Currency symbols can have exchange rates |
class ScalableAdditive a where Source #
Things that can be scaled (or shrinked) with scalars, and added (subtracted) together (like money or a mining hashrate)
ScalableAdditive (Money a) Source # | Money can be |
data ExchangeRates Source #
A dictionary of exchange rates (indexed by pairs of base and foreign currency symbols)
makeExchangeRates :: (CurrencySymbol a, CurrencySymbol b) => [((a, b), Double)] -> ExchangeRates Source #
Construct the exchange dictionary from instances of CurrencySymbol
Polymorphic type representing money
makeMoney :: CurrencySymbol a => Double -> a -> Money a Source #
Money constructor over currency symbols
findRate :: (CurrencySymbol a, CurrencySymbol b) => ExchangeRates -> a -> b -> Maybe Double Source #
Returns the direct conversion rate or tries to compute the reverse one
exchangeTo :: (CurrencySymbol a, CurrencySymbol b) => ExchangeRates -> Money a -> b -> Maybe (Money b) Source #
Maybe convert the money to designated currency symbol
sampleRates :: ExchangeRates Source #
Sample rates dictionary (19 Jan 2017)