2007-07-02 20:43:14 +04:00
|
|
|
module Currency
|
|
|
|
where
|
2007-07-04 06:24:33 +04:00
|
|
|
import qualified Data.Map as Map
|
|
|
|
import Data.Map ((!))
|
2007-07-02 20:43:14 +04:00
|
|
|
import Utils
|
|
|
|
import Types
|
|
|
|
|
|
|
|
currencies =
|
|
|
|
[
|
|
|
|
Currency "$" 1
|
|
|
|
,Currency "EUR" 0.760383
|
|
|
|
,Currency "£" 0.512527
|
|
|
|
,Currency "h" 60 -- hours
|
|
|
|
,Currency "m" 1 -- minutes
|
|
|
|
]
|
|
|
|
|
2007-07-04 06:24:33 +04:00
|
|
|
currencymap = Map.fromList [(sym, c) | c@(Currency sym rate) <- currencies]
|
|
|
|
|
2007-07-02 20:43:14 +04:00
|
|
|
getcurrency :: String -> Currency
|
2007-07-04 06:24:33 +04:00
|
|
|
getcurrency s = Map.findWithDefault (Currency s 1) s currencymap
|
2007-07-02 20:43:14 +04:00
|
|
|
|
|
|
|
conversionRate :: Currency -> Currency -> Double
|
|
|
|
conversionRate oldc newc = (rate newc) / (rate oldc)
|
|
|
|
|
|
|
|
-- convenient amount constructors
|
2007-07-04 05:38:56 +04:00
|
|
|
dollars n = Amount (getcurrency "$") n 2
|
|
|
|
euro n = Amount (getcurrency "EUR") n 2
|
|
|
|
pounds n = Amount (getcurrency "£") n 2
|
|
|
|
hours n = Amount (getcurrency "h") n 2
|
|
|
|
minutes n = Amount (getcurrency "m") n 2
|
2007-07-02 20:43:14 +04:00
|
|
|
|