never executed always true always false
    1 -- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
    2 -- Edit the ORIGNAL .chs file instead!
    3 
    4 
    5 module QuantLib.Currency
    6   (
    7    MoneyConversionType(..)
    8   , ExchangeRateType(..)
    9   , Ccy(..)
   10   , Currency
   11   , currency
   12   , currency'
   13   , code
   14   , fractionsPerUnit
   15   , fractionSymbol
   16   , code'
   17   , symbol
   18   , ExchangeRate
   19   , exchangeRate
   20   , rate
   21   , exchangeRateType
   22   , exchange
   23   , chainExchangeRate
   24   , addExchangeRate
   25   , lookupExchangeRate
   26   , clearExchangeRates
   27   , moneyConversionType
   28   , setMoneyConversionType
   29   , moneyBaseCurrency
   30   , setMoneyBaseCurrency
   31   , convertToBaseCurrency
   32   ) where
   33 import qualified Foreign.C.String as C2HSImp
   34 import qualified Foreign.C.Types as C2HSImp
   35 import qualified Foreign.ForeignPtr as C2HSImp
   36 import qualified Foreign.Ptr as C2HSImp
   37 import qualified System.IO.Unsafe as C2HSImp
   38 
   39 
   40 import QuantLib.Internal
   41 import QuantLib.Internal.Type
   42 import QuantLib.Internal.Common
   43 import Foreign.Marshal.Alloc(alloca)
   44 
   45 
   46 
   47 
   48 
   49 
   50 
   51 
   52 
   53 
   54 data MoneyConversionType = NoConversion
   55                          | BaseCurrencyConversion
   56                          | AutomatedConversion
   57   deriving (Enum,Show,Eq,Read)
   58 
   59 
   60 data ExchangeRateType = Direct
   61                       | Derived
   62   deriving (Enum,Show,Eq,Read)
   63 
   64 
   65 data Ccy = ARS
   66          | ATS
   67          | AUD
   68          | BCH
   69          | BDT
   70          | BEF
   71          | BGL
   72          | BRL
   73          | BTC
   74          | BYR
   75          | CAD
   76          | CHF
   77          | CLP
   78          | CNY
   79          | COP
   80          | CYP
   81          | CZK
   82          | DASH
   83          | DEM
   84          | DKK
   85          | EEK
   86          | ESP
   87          | ETC
   88          | ETH
   89          | EUR
   90          | FIM
   91          | FRF
   92          | GBP
   93          | GRD
   94          | HKD
   95          | HUF
   96          | IDR
   97          | IEP
   98          | ILS
   99          | INR
  100          | IQD
  101          | IRR
  102          | ISK
  103          | ITL
  104          | JPY
  105          | KRW
  106          | KWD
  107          | KZT
  108          | LTC
  109          | LTL
  110          | LUF
  111          | LVL
  112          | MTL
  113          | MXN
  114          | MYR
  115          | NGN
  116          | NLG
  117          | NOK
  118          | NPR
  119          | NZD
  120          | PEH
  121          | PEI
  122          | PEN
  123          | PKR
  124          | PLN
  125          | PTE
  126          | ROL
  127          | RON
  128          | RUB
  129          | SAR
  130          | SEK
  131          | SGD
  132          | SIT
  133          | SKK
  134          | THB
  135          | TRL
  136          | TRY
  137          | TTD
  138          | TWD
  139          | UAH
  140          | USD
  141          | VEB
  142          | VND
  143          | XRP
  144          | ZAR
  145          | ZEC
  146          | AED
  147          | AOA
  148          | BGN
  149          | BHD
  150          | BWP
  151          | CLF
  152          | CNH
  153          | COU
  154          | EGP
  155          | ETB
  156          | GEL
  157          | GHS
  158          | HRK
  159          | JOD
  160          | KES
  161          | LKR
  162          | MAD
  163          | MKD
  164          | MUR
  165          | MXV
  166          | OMR
  167          | PHP
  168          | QAR
  169          | RSD
  170          | TND
  171          | UGX
  172          | UYU
  173          | UZS
  174          | XOF
  175          | ZMW
  176   deriving (Show,Eq,Read,Bounded)
  177 instance Enum Ccy where
  178   succ ARS = ATS
  179   succ ATS = AUD
  180   succ AUD = BCH
  181   succ BCH = BDT
  182   succ BDT = BEF
  183   succ BEF = BGL
  184   succ BGL = BRL
  185   succ BRL = BTC
  186   succ BTC = BYR
  187   succ BYR = CAD
  188   succ CAD = CHF
  189   succ CHF = CLP
  190   succ CLP = CNY
  191   succ CNY = COP
  192   succ COP = CYP
  193   succ CYP = CZK
  194   succ CZK = DASH
  195   succ DASH = DEM
  196   succ DEM = DKK
  197   succ DKK = EEK
  198   succ EEK = ESP
  199   succ ESP = ETC
  200   succ ETC = ETH
  201   succ ETH = EUR
  202   succ EUR = FIM
  203   succ FIM = FRF
  204   succ FRF = GBP
  205   succ GBP = GRD
  206   succ GRD = HKD
  207   succ HKD = HUF
  208   succ HUF = IDR
  209   succ IDR = IEP
  210   succ IEP = ILS
  211   succ ILS = INR
  212   succ INR = IQD
  213   succ IQD = IRR
  214   succ IRR = ISK
  215   succ ISK = ITL
  216   succ ITL = JPY
  217   succ JPY = KRW
  218   succ KRW = KWD
  219   succ KWD = KZT
  220   succ KZT = LTC
  221   succ LTC = LTL
  222   succ LTL = LUF
  223   succ LUF = LVL
  224   succ LVL = MTL
  225   succ MTL = MXN
  226   succ MXN = MYR
  227   succ MYR = NGN
  228   succ NGN = NLG
  229   succ NLG = NOK
  230   succ NOK = NPR
  231   succ NPR = NZD
  232   succ NZD = PEH
  233   succ PEH = PEI
  234   succ PEI = PEN
  235   succ PEN = PKR
  236   succ PKR = PLN
  237   succ PLN = PTE
  238   succ PTE = ROL
  239   succ ROL = RON
  240   succ RON = RUB
  241   succ RUB = SAR
  242   succ SAR = SEK
  243   succ SEK = SGD
  244   succ SGD = SIT
  245   succ SIT = SKK
  246   succ SKK = THB
  247   succ THB = TRL
  248   succ TRL = TRY
  249   succ TRY = TTD
  250   succ TTD = TWD
  251   succ TWD = UAH
  252   succ UAH = USD
  253   succ USD = VEB
  254   succ VEB = VND
  255   succ VND = XRP
  256   succ XRP = ZAR
  257   succ ZAR = ZEC
  258   succ ZEC = AED
  259   succ AED = AOA
  260   succ AOA = BGN
  261   succ BGN = BHD
  262   succ BHD = BWP
  263   succ BWP = CLF
  264   succ CLF = CNH
  265   succ CNH = COU
  266   succ COU = EGP
  267   succ EGP = ETB
  268   succ ETB = GEL
  269   succ GEL = GHS
  270   succ GHS = HRK
  271   succ HRK = JOD
  272   succ JOD = KES
  273   succ KES = LKR
  274   succ LKR = MAD
  275   succ MAD = MKD
  276   succ MKD = MUR
  277   succ MUR = MXV
  278   succ MXV = OMR
  279   succ OMR = PHP
  280   succ PHP = QAR
  281   succ QAR = RSD
  282   succ RSD = TND
  283   succ TND = UGX
  284   succ UGX = UYU
  285   succ UYU = UZS
  286   succ UZS = XOF
  287   succ XOF = ZMW
  288   succ ZMW = error "Ccy.succ: ZMW has no successor"
  289 
  290   pred ATS = ARS
  291   pred AUD = ATS
  292   pred BCH = AUD
  293   pred BDT = BCH
  294   pred BEF = BDT
  295   pred BGL = BEF
  296   pred BRL = BGL
  297   pred BTC = BRL
  298   pred BYR = BTC
  299   pred CAD = BYR
  300   pred CHF = CAD
  301   pred CLP = CHF
  302   pred CNY = CLP
  303   pred COP = CNY
  304   pred CYP = COP
  305   pred CZK = CYP
  306   pred DASH = CZK
  307   pred DEM = DASH
  308   pred DKK = DEM
  309   pred EEK = DKK
  310   pred ESP = EEK
  311   pred ETC = ESP
  312   pred ETH = ETC
  313   pred EUR = ETH
  314   pred FIM = EUR
  315   pred FRF = FIM
  316   pred GBP = FRF
  317   pred GRD = GBP
  318   pred HKD = GRD
  319   pred HUF = HKD
  320   pred IDR = HUF
  321   pred IEP = IDR
  322   pred ILS = IEP
  323   pred INR = ILS
  324   pred IQD = INR
  325   pred IRR = IQD
  326   pred ISK = IRR
  327   pred ITL = ISK
  328   pred JPY = ITL
  329   pred KRW = JPY
  330   pred KWD = KRW
  331   pred KZT = KWD
  332   pred LTC = KZT
  333   pred LTL = LTC
  334   pred LUF = LTL
  335   pred LVL = LUF
  336   pred MTL = LVL
  337   pred MXN = MTL
  338   pred MYR = MXN
  339   pred NGN = MYR
  340   pred NLG = NGN
  341   pred NOK = NLG
  342   pred NPR = NOK
  343   pred NZD = NPR
  344   pred PEH = NZD
  345   pred PEI = PEH
  346   pred PEN = PEI
  347   pred PKR = PEN
  348   pred PLN = PKR
  349   pred PTE = PLN
  350   pred ROL = PTE
  351   pred RON = ROL
  352   pred RUB = RON
  353   pred SAR = RUB
  354   pred SEK = SAR
  355   pred SGD = SEK
  356   pred SIT = SGD
  357   pred SKK = SIT
  358   pred THB = SKK
  359   pred TRL = THB
  360   pred TRY = TRL
  361   pred TTD = TRY
  362   pred TWD = TTD
  363   pred UAH = TWD
  364   pred USD = UAH
  365   pred VEB = USD
  366   pred VND = VEB
  367   pred XRP = VND
  368   pred ZAR = XRP
  369   pred ZEC = ZAR
  370   pred AED = ZEC
  371   pred AOA = AED
  372   pred BGN = AOA
  373   pred BHD = BGN
  374   pred BWP = BHD
  375   pred CLF = BWP
  376   pred CNH = CLF
  377   pred COU = CNH
  378   pred EGP = COU
  379   pred ETB = EGP
  380   pred GEL = ETB
  381   pred GHS = GEL
  382   pred HRK = GHS
  383   pred JOD = HRK
  384   pred KES = JOD
  385   pred LKR = KES
  386   pred MAD = LKR
  387   pred MKD = MAD
  388   pred MUR = MKD
  389   pred MXV = MUR
  390   pred OMR = MXV
  391   pred PHP = OMR
  392   pred QAR = PHP
  393   pred RSD = QAR
  394   pred TND = RSD
  395   pred UGX = TND
  396   pred UYU = UGX
  397   pred UZS = UYU
  398   pred XOF = UZS
  399   pred ZMW = XOF
  400   pred ARS = error "Ccy.pred: ARS has no predecessor"
  401 
  402   enumFromTo from to = go from
  403     where
  404       end = fromEnum to
  405       go v = case compare (fromEnum v) end of
  406                  LT -> v : go (succ v)
  407                  EQ -> [v]
  408                  GT -> []
  409 
  410   enumFrom from = enumFromTo from ZMW
  411 
  412   fromEnum ARS = 0
  413   fromEnum ATS = 1
  414   fromEnum AUD = 2
  415   fromEnum BCH = 3
  416   fromEnum BDT = 4
  417   fromEnum BEF = 5
  418   fromEnum BGL = 6
  419   fromEnum BRL = 7
  420   fromEnum BTC = 8
  421   fromEnum BYR = 9
  422   fromEnum CAD = 10
  423   fromEnum CHF = 11
  424   fromEnum CLP = 12
  425   fromEnum CNY = 13
  426   fromEnum COP = 14
  427   fromEnum CYP = 15
  428   fromEnum CZK = 16
  429   fromEnum DASH = 17
  430   fromEnum DEM = 18
  431   fromEnum DKK = 19
  432   fromEnum EEK = 20
  433   fromEnum ESP = 21
  434   fromEnum ETC = 22
  435   fromEnum ETH = 23
  436   fromEnum EUR = 24
  437   fromEnum FIM = 25
  438   fromEnum FRF = 26
  439   fromEnum GBP = 27
  440   fromEnum GRD = 28
  441   fromEnum HKD = 29
  442   fromEnum HUF = 30
  443   fromEnum IDR = 31
  444   fromEnum IEP = 32
  445   fromEnum ILS = 33
  446   fromEnum INR = 34
  447   fromEnum IQD = 35
  448   fromEnum IRR = 36
  449   fromEnum ISK = 37
  450   fromEnum ITL = 38
  451   fromEnum JPY = 39
  452   fromEnum KRW = 40
  453   fromEnum KWD = 41
  454   fromEnum KZT = 42
  455   fromEnum LTC = 43
  456   fromEnum LTL = 44
  457   fromEnum LUF = 45
  458   fromEnum LVL = 46
  459   fromEnum MTL = 47
  460   fromEnum MXN = 48
  461   fromEnum MYR = 49
  462   fromEnum NGN = 50
  463   fromEnum NLG = 51
  464   fromEnum NOK = 52
  465   fromEnum NPR = 53
  466   fromEnum NZD = 54
  467   fromEnum PEH = 55
  468   fromEnum PEI = 56
  469   fromEnum PEN = 57
  470   fromEnum PKR = 58
  471   fromEnum PLN = 59
  472   fromEnum PTE = 60
  473   fromEnum ROL = 61
  474   fromEnum RON = 62
  475   fromEnum RUB = 63
  476   fromEnum SAR = 64
  477   fromEnum SEK = 65
  478   fromEnum SGD = 66
  479   fromEnum SIT = 67
  480   fromEnum SKK = 68
  481   fromEnum THB = 69
  482   fromEnum TRL = 70
  483   fromEnum TRY = 71
  484   fromEnum TTD = 72
  485   fromEnum TWD = 73
  486   fromEnum UAH = 74
  487   fromEnum USD = 75
  488   fromEnum VEB = 76
  489   fromEnum VND = 77
  490   fromEnum XRP = 78
  491   fromEnum ZAR = 79
  492   fromEnum ZEC = 80
  493   fromEnum AED = 81
  494   fromEnum AOA = 82
  495   fromEnum BGN = 83
  496   fromEnum BHD = 84
  497   fromEnum BWP = 85
  498   fromEnum CLF = 86
  499   fromEnum CNH = 87
  500   fromEnum COU = 88
  501   fromEnum EGP = 89
  502   fromEnum ETB = 90
  503   fromEnum GEL = 91
  504   fromEnum GHS = 92
  505   fromEnum HRK = 93
  506   fromEnum JOD = 94
  507   fromEnum KES = 95
  508   fromEnum LKR = 96
  509   fromEnum MAD = 97
  510   fromEnum MKD = 98
  511   fromEnum MUR = 99
  512   fromEnum MXV = 100
  513   fromEnum OMR = 101
  514   fromEnum PHP = 102
  515   fromEnum QAR = 103
  516   fromEnum RSD = 104
  517   fromEnum TND = 105
  518   fromEnum UGX = 106
  519   fromEnum UYU = 107
  520   fromEnum UZS = 108
  521   fromEnum XOF = 109
  522   fromEnum ZMW = 110
  523 
  524   toEnum 0 = ARS
  525   toEnum 1 = ATS
  526   toEnum 2 = AUD
  527   toEnum 3 = BCH
  528   toEnum 4 = BDT
  529   toEnum 5 = BEF
  530   toEnum 6 = BGL
  531   toEnum 7 = BRL
  532   toEnum 8 = BTC
  533   toEnum 9 = BYR
  534   toEnum 10 = CAD
  535   toEnum 11 = CHF
  536   toEnum 12 = CLP
  537   toEnum 13 = CNY
  538   toEnum 14 = COP
  539   toEnum 15 = CYP
  540   toEnum 16 = CZK
  541   toEnum 17 = DASH
  542   toEnum 18 = DEM
  543   toEnum 19 = DKK
  544   toEnum 20 = EEK
  545   toEnum 21 = ESP
  546   toEnum 22 = ETC
  547   toEnum 23 = ETH
  548   toEnum 24 = EUR
  549   toEnum 25 = FIM
  550   toEnum 26 = FRF
  551   toEnum 27 = GBP
  552   toEnum 28 = GRD
  553   toEnum 29 = HKD
  554   toEnum 30 = HUF
  555   toEnum 31 = IDR
  556   toEnum 32 = IEP
  557   toEnum 33 = ILS
  558   toEnum 34 = INR
  559   toEnum 35 = IQD
  560   toEnum 36 = IRR
  561   toEnum 37 = ISK
  562   toEnum 38 = ITL
  563   toEnum 39 = JPY
  564   toEnum 40 = KRW
  565   toEnum 41 = KWD
  566   toEnum 42 = KZT
  567   toEnum 43 = LTC
  568   toEnum 44 = LTL
  569   toEnum 45 = LUF
  570   toEnum 46 = LVL
  571   toEnum 47 = MTL
  572   toEnum 48 = MXN
  573   toEnum 49 = MYR
  574   toEnum 50 = NGN
  575   toEnum 51 = NLG
  576   toEnum 52 = NOK
  577   toEnum 53 = NPR
  578   toEnum 54 = NZD
  579   toEnum 55 = PEH
  580   toEnum 56 = PEI
  581   toEnum 57 = PEN
  582   toEnum 58 = PKR
  583   toEnum 59 = PLN
  584   toEnum 60 = PTE
  585   toEnum 61 = ROL
  586   toEnum 62 = RON
  587   toEnum 63 = RUB
  588   toEnum 64 = SAR
  589   toEnum 65 = SEK
  590   toEnum 66 = SGD
  591   toEnum 67 = SIT
  592   toEnum 68 = SKK
  593   toEnum 69 = THB
  594   toEnum 70 = TRL
  595   toEnum 71 = TRY
  596   toEnum 72 = TTD
  597   toEnum 73 = TWD
  598   toEnum 74 = UAH
  599   toEnum 75 = USD
  600   toEnum 76 = VEB
  601   toEnum 77 = VND
  602   toEnum 78 = XRP
  603   toEnum 79 = ZAR
  604   toEnum 80 = ZEC
  605   toEnum 81 = AED
  606   toEnum 82 = AOA
  607   toEnum 83 = BGN
  608   toEnum 84 = BHD
  609   toEnum 85 = BWP
  610   toEnum 86 = CLF
  611   toEnum 87 = CNH
  612   toEnum 88 = COU
  613   toEnum 89 = EGP
  614   toEnum 90 = ETB
  615   toEnum 91 = GEL
  616   toEnum 92 = GHS
  617   toEnum 93 = HRK
  618   toEnum 94 = JOD
  619   toEnum 95 = KES
  620   toEnum 96 = LKR
  621   toEnum 97 = MAD
  622   toEnum 98 = MKD
  623   toEnum 99 = MUR
  624   toEnum 100 = MXV
  625   toEnum 101 = OMR
  626   toEnum 102 = PHP
  627   toEnum 103 = QAR
  628   toEnum 104 = RSD
  629   toEnum 105 = TND
  630   toEnum 106 = UGX
  631   toEnum 107 = UYU
  632   toEnum 108 = UZS
  633   toEnum 109 = XOF
  634   toEnum 110 = ZMW
  635   toEnum unmatched = error ("Ccy.toEnum: Cannot match " ++ show unmatched)
  636 
  637 
  638 
  639 
  640 
  641 
  642 
  643 
  644 
  645 
  646 -- |Look up one of the built-in ISO 4217 currencies by its enum tag.
  647 currency :: (Ccy) -> IO ((Currency))
  648 currency a1 =
  649   let {a1' = (fromIntegral . fromEnum) a1} in 
  650   preErrorCheck $ \a2' -> 
  651   currency'_ a1' a2' >>= \res ->
  652   peekCurrency res >>= \res' ->
  653   errorCheck  a2'>>
  654   return (res')
  655 
  656 
  657 
  658 -- |The currency's ISO 4217 three-letter code, e.g. \"USD\".
  659 code :: (Currency) -> (String)
  660 code a1 =
  661   C2HSImp.unsafePerformIO $
  662   withCurrency a1 $ \a1' -> 
  663   code'_ a1' >>= \res ->
  664   peekDynString res >>= \res' ->
  665   return (res')
  666 
  667 
  668 
  669 -- |The number of fractional units (e.g. cents) in one unit of the currency.
  670 fractionsPerUnit :: (Currency) -> (Int)
  671 fractionsPerUnit a1 =
  672   C2HSImp.unsafePerformIO $
  673   withCurrency a1 $ \a1' -> 
  674   fractionsPerUnit'_ a1' >>= \res ->
  675   let {res' = fromIntegral res} in
  676   return (res')
  677 
  678 
  679 
  680 -- |The currency's fractional-unit symbol, e.g. \"ยข\".
  681 fractionSymbol :: (Currency) -> (String)
  682 fractionSymbol a1 =
  683   C2HSImp.unsafePerformIO $
  684   withCurrency a1 $ \a1' -> 
  685   fractionSymbol'_ a1' >>= \res ->
  686   C2HSImp.peekCString res >>= \res' ->
  687   return (res')
  688 
  689 
  690 
  691 -- |The currency's ISO 4217 numeric code, e.g. 840 for USD.
  692 code' :: (Currency) -> (Int)
  693 code' a1 =
  694   C2HSImp.unsafePerformIO $
  695   withCurrency a1 $ \a1' -> 
  696   code''_ a1' >>= \res ->
  697   let {res' = fromIntegral res} in
  698   return (res')
  699 
  700 
  701 
  702 -- |The currency's symbol, e.g. \"$\".
  703 symbol :: (Currency) -> (String)
  704 symbol a1 =
  705   C2HSImp.unsafePerformIO $
  706   withCurrency a1 $ \a1' -> 
  707   symbol'_ a1' >>= \res ->
  708   C2HSImp.peekCString res >>= \res' ->
  709   return (res')
  710 
  711 
  712 
  713 -- |Construct a custom currency from its name, codes, symbols, rounding convention and an
  714 -- optional triangulation currency used for indirect exchange.
  715 currency' :: (String) -- ^name
  716  -> (String) -- ^code
  717  -> (Int) -- ^numericCode
  718  -> (String) -- ^symbol
  719  -> (String) -- ^fractionSymbol
  720  -> (Int) -- ^fractionsPerUnit
  721  -> (Maybe Rounding) -> (Maybe Currency) -- ^triangulationCurrency
  722  -> IO ((Currency))
  723 currency' a1 a2 a3 a4 a5 a6 a7 a8 =
  724   C2HSImp.withCString a1 $ \a1' -> 
  725   C2HSImp.withCString a2 $ \a2' -> 
  726   let {a3' = fromIntegral a3} in 
  727   C2HSImp.withCString a4 $ \a4' -> 
  728   C2HSImp.withCString a5 $ \a5' -> 
  729   let {a6' = fromIntegral a6} in 
  730   withMaybeRounding a7 $ \a7' -> 
  731   withMaybeCurrency a8 $ \a8' -> 
  732   preErrorCheck $ \a9' -> 
  733   currency''_ a1' a2' a3' a4' a5' a6' a7' a8' a9' >>= \res ->
  734   peekCurrency res >>= \res' ->
  735   errorCheck  a9'>>
  736   return (res')
  737 
  738 
  739 
  740 -- |Construct a Direct exchange rate: a unit of @source@ is worth @rate@ units of @target@.
  741 exchangeRate :: (Currency) -- ^source
  742  -> (Currency) -- ^target
  743  -> (Double) -- ^rate
  744  -> IO ((ExchangeRate))
  745 exchangeRate a1 a2 a3 =
  746   withCurrency a1 $ \a1' -> 
  747   withCurrency a2 $ \a2' -> 
  748   let {a3' = realToFrac a3} in 
  749   preErrorCheck $ \a4' -> 
  750   exchangeRate'_ a1' a2' a3' a4' >>= \res ->
  751   peekExchangeRate res >>= \res' ->
  752   errorCheck  a4'>>
  753   return (res')
  754 
  755 
  756 
  757 -- |The rate itself: a unit of the source currency is worth this many units of the target.
  758 rate :: (ExchangeRate) -> IO ((Double))
  759 rate a1 =
  760   withExchangeRate a1 $ \a1' -> 
  761   rate'_ a1' >>= \res ->
  762   let {res' = realToFrac res} in
  763   return (res')
  764 
  765 
  766 
  767 -- |Whether the rate was given directly or derived by chaining two other rates.
  768 exchangeRateType :: (ExchangeRate) -> IO ((ExchangeRateType))
  769 exchangeRateType a1 =
  770   withExchangeRate a1 $ \a1' -> 
  771   exchangeRateType'_ a1' >>= \res ->
  772   let {res' = (toEnum . fromIntegral) res} in
  773   return (res')
  774 
  775 
  776 
  777 -- |Apply an exchange rate to a cash amount (a @(Double, Currency)@ pair, standing in for
  778 -- QuantLib's @Money@), returning the converted amount as a pair in the other currency of the
  779 -- rate. Throws if the given currency is on neither side of the rate.
  780 exchange :: (ExchangeRate) -> ((Double, Currency)) -- ^amount
  781  -> IO ((Double), (Currency))
  782 exchange a1 a2 =
  783   withExchangeRate a1 $ \a1' -> 
  784   withMoney a2 $ \(a2'1, a2'2) -> 
  785   alloca $ \a3' -> 
  786   preErrorCheck $ \a4' -> 
  787   exchange'_ a1' a2'1  a2'2 a3' a4' >>= \res ->
  788   let {res' = realToFrac res} in
  789   peekCurrencyPtr  a3'>>= \a3'' -> 
  790   errorCheck  a4'>>
  791   return (res', a3'')
  792 
  793 
  794 
  795 -- |Combine two exchange rates sharing a common currency into a derived rate between their
  796 -- other two currencies. Throws if the rates don't share a common currency.
  797 chainExchangeRate :: (ExchangeRate) -> (ExchangeRate) -> IO ((ExchangeRate))
  798 chainExchangeRate a1 a2 =
  799   withExchangeRate a1 $ \a1' -> 
  800   withExchangeRate a2 $ \a2' -> 
  801   preErrorCheck $ \a3' -> 
  802   chainExchangeRate'_ a1' a2' a3' >>= \res ->
  803   peekExchangeRate res >>= \res' ->
  804   errorCheck  a3'>>
  805   return (res')
  806 
  807 
  808 
  809 -- |Register an exchange rate with the global exchange-rate repository, valid between the given
  810 -- dates (inclusive). Use 'minDate'/'maxDate' for an always-valid rate.
  811 addExchangeRate :: (ExchangeRate) -> (Day) -> (Day) -> IO ()
  812 addExchangeRate a1 a2 a3 =
  813   withExchangeRate a1 $ \a1' -> 
  814   withDay a2 $ \a2' -> 
  815   withDay a3 $ \a3' -> 
  816   preErrorCheck $ \a4' -> 
  817   addExchangeRate'_ a1' a2' a3' a4' >>
  818   errorCheck  a4'>>
  819   return ()
  820 
  821 
  822 
  823 -- |Look up a (possibly derived) exchange rate between two currencies at a given date (or the
  824 -- current evaluation date if 'Nothing'). Throws if no rate can be found. Pre-populated with a
  825 -- set of known historical rates even before any 'addExchangeRate' call.
  826 lookupExchangeRate :: (Currency) -> (Currency) -> (Maybe Day) -> (ExchangeRateType) -> IO ((ExchangeRate))
  827 lookupExchangeRate a1 a2 a3 a4 =
  828   withCurrency a1 $ \a1' -> 
  829   withCurrency a2 $ \a2' -> 
  830   withMaybeDay a3 $ \a3' -> 
  831   let {a4' = (fromIntegral . fromEnum) a4} in 
  832   preErrorCheck $ \a5' -> 
  833   lookupExchangeRate'_ a1' a2' a3' a4' a5' >>= \res ->
  834   peekExchangeRate res >>= \res' ->
  835   errorCheck  a5'>>
  836   return (res')
  837 
  838 
  839 
  840 -- |Reset the exchange-rate repository back to its built-in set of known historical rates,
  841 -- discarding anything added via 'addExchangeRate'.
  842 clearExchangeRates :: IO ()
  843 clearExchangeRates =
  844   clearExchangeRates'_ >>
  845   return ()
  846 
  847 
  848 
  849 -- |The global 'Money' arithmetic setting controlling how amounts in different currencies are
  850 -- combined (no conversion, convert to the base currency, or convert automatically).
  851 moneyConversionType :: IO ((MoneyConversionType))
  852 moneyConversionType =
  853   moneyConversionType'_ >>= \res ->
  854   let {res' = (toEnum . fromIntegral) res} in
  855   return (res')
  856 
  857 
  858 
  859 -- |Set the global 'Money' arithmetic conversion setting.
  860 setMoneyConversionType :: (MoneyConversionType) -> IO ()
  861 setMoneyConversionType a1 =
  862   let {a1' = (fromIntegral . fromEnum) a1} in 
  863   setMoneyConversionType'_ a1' >>
  864   return ()
  865 
  866 
  867 
  868 -- |The global base currency used by 'MoneyConversionType' base-currency conversion, if set.
  869 moneyBaseCurrency :: IO ((Maybe Currency))
  870 moneyBaseCurrency =
  871   preErrorCheck $ \a1' -> 
  872   moneyBaseCurrency'_ a1' >>= \res ->
  873   peekMaybeCurrency res >>= \res' ->
  874   errorCheck  a1'>>
  875   return (res')
  876 
  877 
  878 
  879 -- |Set the global base currency used by 'MoneyConversionType' base-currency conversion.
  880 setMoneyBaseCurrency :: (Currency) -> IO ()
  881 setMoneyBaseCurrency a1 =
  882   withCurrency a1 $ \a1' -> 
  883   setMoneyBaseCurrency'_ a1' >>
  884   return ()
  885 
  886 
  887 
  888 -- |Convert a cash amount to the configured base currency (via 'setMoneyBaseCurrency'), using
  889 -- 'lookupExchangeRate' and rounding the result per the target currency's convention. Throws if
  890 -- no base currency is set or no rate path exists.
  891 convertToBaseCurrency :: ((Double, Currency)) -- ^amount
  892  -> IO ((Double), (Currency))
  893 convertToBaseCurrency a1 =
  894   withMoney a1 $ \(a1'1, a1'2) -> 
  895   alloca $ \a2' -> 
  896   preErrorCheck $ \a3' -> 
  897   convertToBaseCurrency'_ a1'1  a1'2 a2' a3' >>= \res ->
  898   let {res' = realToFrac res} in
  899   peekCurrencyPtr  a2'>>= \a2'' -> 
  900   errorCheck  a3'>>
  901   return (res', a2'')
  902 
  903 
  904 
  905 -- vim: set ff=unix ts=8 sts=2 sw=2 et:
  906 
  907 foreign import ccall safe "QuantLib/Currency.chs.h qlCurrency"
  908   currency'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCurrency)))))
  909 
  910 foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyCode"
  911   code'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
  912 
  913 foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyFractionsPerUnit"
  914   fractionsPerUnit'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO C2HSImp.CInt))
  915 
  916 foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyFractionSymbol"
  917   fractionSymbol'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
  918 
  919 foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyNumericCode"
  920   code''_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO C2HSImp.CInt))
  921 
  922 foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencySymbol"
  923   symbol'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))
  924 
  925 foreign import ccall safe "QuantLib/Currency.chs.h qlCreateCurrency"
  926   currency''_ :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> ((C2HSImp.Ptr (CRounding)) -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCurrency))))))))))))
  927 
  928 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRate"
  929   exchangeRate'_ :: ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CExchangeRate)))))))
  930 
  931 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateRate"
  932   rate'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (IO C2HSImp.CDouble))
  933 
  934 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateType_"
  935   exchangeRateType'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (IO C2HSImp.CInt))
  936 
  937 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateExchange"
  938   exchange'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CCurrency))) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble))))))
  939 
  940 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateChain"
  941   chainExchangeRate'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> ((C2HSImp.Ptr (CExchangeRate)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CExchangeRate))))))
  942 
  943 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateManagerAdd"
  944   addExchangeRate'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ())))))
  945 
  946 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateManagerLookup"
  947   lookupExchangeRate'_ :: ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CExchangeRate))))))))
  948 
  949 foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateManagerClear"
  950   clearExchangeRates'_ :: (IO ())
  951 
  952 foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsConversionType"
  953   moneyConversionType'_ :: (IO C2HSImp.CInt)
  954 
  955 foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsSetConversionType"
  956   setMoneyConversionType'_ :: (C2HSImp.CInt -> (IO ()))
  957 
  958 foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsBaseCurrency"
  959   moneyBaseCurrency'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CCurrency))))
  960 
  961 foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsSetBaseCurrency"
  962   setMoneyBaseCurrency'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO ()))
  963 
  964 foreign import ccall safe "QuantLib/Currency.chs.h qlConvertToBaseCurrency"
  965   convertToBaseCurrency'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CCurrency))) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))