1 {-| 2 3 A 'Commodity' is a symbol representing a currency or some other kind of 4 thing we are tracking, and some display preferences that tell how to 5 display 'Amount's of the commodity - is the symbol on the left or right, 6 are thousands separated by comma, significant decimal places and so on. 7 8 -} 9 module Ledger.Commodity 10 where 11 import qualified Data.Map as Map 12 import Ledger.Utils 13 import Ledger.Types 14 15 16 -- convenient amount and commodity constructors, for tests etc. 17 18 unknown = Commodity {symbol="", side=L,spaced=False,comma=False,precision=0} 19 dollar = Commodity {symbol="$", side=L,spaced=False,comma=False,precision=2} 20 euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2} 21 pound = Commodity {symbol="£", side=L,spaced=False,comma=False,precision=2} 22 hour = Commodity {symbol="h", side=R,spaced=False,comma=False,precision=1} 23 24 dollars n = Amount dollar n Nothing 25 euros n = Amount euro n Nothing 26 pounds n = Amount pound n Nothing 27 hours n = Amount hour n Nothing 28 29 defaultcommodities = [dollar, euro, pound, hour, unknown] 30 31 -- | Look up one of the hard-coded default commodities. For use in tests. 32 comm :: String -> Commodity 33 comm sym = fromMaybe 34 (error "commodity lookup failed") 35 $ find (\(Commodity{symbol=s}) -> s==sym) defaultcommodities 36 37 -- | Find the conversion rate between two commodities. Currently returns 1. 38 conversionRate :: Commodity -> Commodity -> Double 39 conversionRate oldc newc = 1 40