-- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./QuantLib/Currency.chs" #-}
module QuantLib.Currency
  (
    -- * Types
    -- ** Currencies
    Currency
  , Ccy(..)
    -- ** Exchange rates and money
  , ExchangeRate
  , ExchangeRateType(..)
  , MoneyConversionType(..)

    -- * Constructors
    -- ** Currencies
  , currency
  , customCurrency
    -- ** Exchange rates
  , exchangeRate
  , chainExchangeRate

    -- * Mutators
  , addExchangeRate
  , clearExchangeRates
  , setMoneyConversionType
  , setMoneyBaseCurrency

    -- * Inspectors
    -- ** Currency conversion
  , exchange
  , convertToBaseCurrency
    -- ** Currencies
  , code
  , fractionsPerUnit
  , fractionSymbol
  , numericCode
  , symbol
    -- ** Exchange rates and settings
  , rate
  , exchangeRateType
  , lookupExchangeRate
  , moneyConversionType
  , moneyBaseCurrency
  ) where
import qualified Foreign.C.String as C2HSImp
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp


import Control.Exception (mask_)
import System.IO.Unsafe (unsafePerformIO)
import QuantLib.Internal
import QuantLib.Internal.Type
import QuantLib.Internal.Common
import Foreign.Marshal.Alloc(alloca)







data MoneyConversionType = NoConversion
                         | BaseCurrencyConversion
                         | AutomatedConversion
  deriving (Enum,Show,Eq,Read)

{-# LINE 56 "./QuantLib/Currency.chs" #-}

data ExchangeRateType = Direct
                      | Derived
  deriving (Enum,Show,Eq,Read)

{-# LINE 57 "./QuantLib/Currency.chs" #-}

data Ccy = ARS
         | ATS
         | AUD
         | BCH
         | BDT
         | BEF
         | BGL
         | BRL
         | BTC
         | BYR
         | CAD
         | CHF
         | CLP
         | CNY
         | COP
         | CYP
         | CZK
         | DASH
         | DEM
         | DKK
         | EEK
         | ESP
         | ETC
         | ETH
         | EUR
         | FIM
         | FRF
         | GBP
         | GRD
         | HKD
         | HUF
         | IDR
         | IEP
         | ILS
         | INR
         | IQD
         | IRR
         | ISK
         | ITL
         | JPY
         | KRW
         | KWD
         | KZT
         | LTC
         | LTL
         | LUF
         | LVL
         | MTL
         | MXN
         | MYR
         | NGN
         | NLG
         | NOK
         | NPR
         | NZD
         | PEH
         | PEI
         | PEN
         | PKR
         | PLN
         | PTE
         | ROL
         | RON
         | RUB
         | SAR
         | SEK
         | SGD
         | SIT
         | SKK
         | THB
         | TRL
         | TRY
         | TTD
         | TWD
         | UAH
         | USD
         | VEB
         | VND
         | XRP
         | ZAR
         | ZEC
         | AED
         | AOA
         | BGN
         | BHD
         | BWP
         | CLF
         | CNH
         | COU
         | EGP
         | ETB
         | GEL
         | GHS
         | HRK
         | JOD
         | KES
         | LKR
         | MAD
         | MKD
         | MUR
         | MXV
         | OMR
         | PHP
         | QAR
         | RSD
         | TND
         | UGX
         | UYU
         | UZS
         | XOF
         | ZMW
  deriving (Show,Eq,Read,Bounded)
instance Enum Ccy where
  succ ARS = ATS
  succ ATS = AUD
  succ AUD = BCH
  succ BCH = BDT
  succ BDT = BEF
  succ BEF = BGL
  succ BGL = BRL
  succ BRL = BTC
  succ BTC = BYR
  succ BYR = CAD
  succ CAD = CHF
  succ CHF = CLP
  succ CLP = CNY
  succ CNY = COP
  succ COP = CYP
  succ CYP = CZK
  succ CZK = DASH
  succ DASH = DEM
  succ DEM = DKK
  succ DKK = EEK
  succ EEK = ESP
  succ ESP = ETC
  succ ETC = ETH
  succ ETH = EUR
  succ EUR = FIM
  succ FIM = FRF
  succ FRF = GBP
  succ GBP = GRD
  succ GRD = HKD
  succ HKD = HUF
  succ HUF = IDR
  succ IDR = IEP
  succ IEP = ILS
  succ ILS = INR
  succ INR = IQD
  succ IQD = IRR
  succ IRR = ISK
  succ ISK = ITL
  succ ITL = JPY
  succ JPY = KRW
  succ KRW = KWD
  succ KWD = KZT
  succ KZT = LTC
  succ LTC = LTL
  succ LTL = LUF
  succ LUF = LVL
  succ LVL = MTL
  succ MTL = MXN
  succ MXN = MYR
  succ MYR = NGN
  succ NGN = NLG
  succ NLG = NOK
  succ NOK = NPR
  succ NPR = NZD
  succ NZD = PEH
  succ PEH = PEI
  succ PEI = PEN
  succ PEN = PKR
  succ PKR = PLN
  succ PLN = PTE
  succ PTE = ROL
  succ ROL = RON
  succ RON = RUB
  succ RUB = SAR
  succ SAR = SEK
  succ SEK = SGD
  succ SGD = SIT
  succ SIT = SKK
  succ SKK = THB
  succ THB = TRL
  succ TRL = TRY
  succ TRY = TTD
  succ TTD = TWD
  succ TWD = UAH
  succ UAH = USD
  succ USD = VEB
  succ VEB = VND
  succ VND = XRP
  succ XRP = ZAR
  succ ZAR = ZEC
  succ ZEC = AED
  succ AED = AOA
  succ AOA = BGN
  succ BGN = BHD
  succ BHD = BWP
  succ BWP = CLF
  succ CLF = CNH
  succ CNH = COU
  succ COU = EGP
  succ EGP = ETB
  succ ETB = GEL
  succ GEL = GHS
  succ GHS = HRK
  succ HRK = JOD
  succ JOD = KES
  succ KES = LKR
  succ LKR = MAD
  succ MAD = MKD
  succ MKD = MUR
  succ MUR = MXV
  succ MXV = OMR
  succ OMR = PHP
  succ PHP = QAR
  succ QAR = RSD
  succ RSD = TND
  succ TND = UGX
  succ UGX = UYU
  succ UYU = UZS
  succ UZS = XOF
  succ XOF = ZMW
  succ ZMW = error "Ccy.succ: ZMW has no successor"

  pred :: Ccy -> Ccy
pred Ccy
ATS = Ccy
ARS
  pred Ccy
AUD = Ccy
ATS
  pred Ccy
BCH = Ccy
AUD
  pred Ccy
BDT = Ccy
BCH
  pred Ccy
BEF = Ccy
BDT
  pred Ccy
BGL = Ccy
BEF
  pred Ccy
BRL = Ccy
BGL
  pred Ccy
BTC = Ccy
BRL
  pred Ccy
BYR = Ccy
BTC
  pred Ccy
CAD = Ccy
BYR
  pred Ccy
CHF = Ccy
CAD
  pred Ccy
CLP = Ccy
CHF
  pred Ccy
CNY = Ccy
CLP
  pred Ccy
COP = Ccy
CNY
  pred Ccy
CYP = Ccy
COP
  pred Ccy
CZK = Ccy
CYP
  pred Ccy
DASH = Ccy
CZK
  pred Ccy
DEM = Ccy
DASH
  pred Ccy
DKK = Ccy
DEM
  pred Ccy
EEK = Ccy
DKK
  pred Ccy
ESP = Ccy
EEK
  pred Ccy
ETC = Ccy
ESP
  pred Ccy
ETH = Ccy
ETC
  pred Ccy
EUR = Ccy
ETH
  pred Ccy
FIM = Ccy
EUR
  pred Ccy
FRF = Ccy
FIM
  pred Ccy
GBP = Ccy
FRF
  pred Ccy
GRD = Ccy
GBP
  pred Ccy
HKD = Ccy
GRD
  pred Ccy
HUF = Ccy
HKD
  pred Ccy
IDR = Ccy
HUF
  pred Ccy
IEP = Ccy
IDR
  pred Ccy
ILS = Ccy
IEP
  pred Ccy
INR = Ccy
ILS
  pred Ccy
IQD = Ccy
INR
  pred Ccy
IRR = Ccy
IQD
  pred Ccy
ISK = Ccy
IRR
  pred Ccy
ITL = Ccy
ISK
  pred Ccy
JPY = Ccy
ITL
  pred Ccy
KRW = Ccy
JPY
  pred Ccy
KWD = Ccy
KRW
  pred Ccy
KZT = Ccy
KWD
  pred Ccy
LTC = Ccy
KZT
  pred Ccy
LTL = Ccy
LTC
  pred Ccy
LUF = Ccy
LTL
  pred Ccy
LVL = Ccy
LUF
  pred Ccy
MTL = Ccy
LVL
  pred Ccy
MXN = Ccy
MTL
  pred Ccy
MYR = Ccy
MXN
  pred Ccy
NGN = Ccy
MYR
  pred Ccy
NLG = Ccy
NGN
  pred Ccy
NOK = Ccy
NLG
  pred Ccy
NPR = Ccy
NOK
  pred Ccy
NZD = Ccy
NPR
  pred Ccy
PEH = Ccy
NZD
  pred Ccy
PEI = Ccy
PEH
  pred Ccy
PEN = Ccy
PEI
  pred Ccy
PKR = Ccy
PEN
  pred Ccy
PLN = Ccy
PKR
  pred Ccy
PTE = Ccy
PLN
  pred Ccy
ROL = Ccy
PTE
  pred Ccy
RON = Ccy
ROL
  pred Ccy
RUB = Ccy
RON
  pred Ccy
SAR = Ccy
RUB
  pred Ccy
SEK = Ccy
SAR
  pred Ccy
SGD = Ccy
SEK
  pred Ccy
SIT = Ccy
SGD
  pred Ccy
SKK = Ccy
SIT
  pred Ccy
THB = Ccy
SKK
  pred Ccy
TRL = Ccy
THB
  pred Ccy
TRY = Ccy
TRL
  pred Ccy
TTD = Ccy
TRY
  pred Ccy
TWD = Ccy
TTD
  pred Ccy
UAH = Ccy
TWD
  pred Ccy
USD = Ccy
UAH
  pred Ccy
VEB = Ccy
USD
  pred Ccy
VND = Ccy
VEB
  pred Ccy
XRP = Ccy
VND
  pred Ccy
ZAR = Ccy
XRP
  pred Ccy
ZEC = Ccy
ZAR
  pred Ccy
AED = Ccy
ZEC
  pred Ccy
AOA = Ccy
AED
  pred Ccy
BGN = Ccy
AOA
  pred Ccy
BHD = Ccy
BGN
  pred Ccy
BWP = Ccy
BHD
  pred Ccy
CLF = Ccy
BWP
  pred Ccy
CNH = Ccy
CLF
  pred Ccy
COU = Ccy
CNH
  pred Ccy
EGP = Ccy
COU
  pred Ccy
ETB = Ccy
EGP
  pred Ccy
GEL = Ccy
ETB
  pred Ccy
GHS = Ccy
GEL
  pred Ccy
HRK = Ccy
GHS
  pred Ccy
JOD = Ccy
HRK
  pred Ccy
KES = Ccy
JOD
  pred Ccy
LKR = Ccy
KES
  pred Ccy
MAD = Ccy
LKR
  pred Ccy
MKD = Ccy
MAD
  pred Ccy
MUR = Ccy
MKD
  pred Ccy
MXV = Ccy
MUR
  pred Ccy
OMR = Ccy
MXV
  pred Ccy
PHP = Ccy
OMR
  pred Ccy
QAR = Ccy
PHP
  pred Ccy
RSD = Ccy
QAR
  pred Ccy
TND = Ccy
RSD
  pred Ccy
UGX = Ccy
TND
  pred Ccy
UYU = Ccy
UGX
  pred Ccy
UZS = Ccy
UYU
  pred Ccy
XOF = Ccy
UZS
  pred Ccy
ZMW = Ccy
XOF
  pred Ccy
ARS = String -> Ccy
forall a. HasCallStack => String -> a
error String
"Ccy.pred: ARS has no predecessor"

  enumFromTo :: Ccy -> Ccy -> [Ccy]
enumFromTo Ccy
from Ccy
to = Ccy -> [Ccy]
forall {t}. Enum t => t -> [t]
go Ccy
from
    where
      end :: Int
end = Ccy -> Int
forall a. Enum a => a -> Int
fromEnum Ccy
to
      go :: t -> [t]
go t
v = case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (t -> Int
forall a. Enum a => a -> Int
fromEnum t
v) Int
end of
                 Ordering
LT -> t
v t -> [t] -> [t]
forall a. a -> [a] -> [a]
: t -> [t]
go (t -> t
forall a. Enum a => a -> a
succ t
v)
                 Ordering
EQ -> [t
v]
                 Ordering
GT -> []

  enumFrom :: Ccy -> [Ccy]
enumFrom Ccy
from = Ccy -> Ccy -> [Ccy]
forall a. Enum a => a -> a -> [a]
enumFromTo Ccy
from Ccy
ZMW

  fromEnum :: Ccy -> Int
fromEnum Ccy
ARS = Int
0
  fromEnum Ccy
ATS = Int
1
  fromEnum Ccy
AUD = Int
2
  fromEnum Ccy
BCH = Int
3
  fromEnum Ccy
BDT = Int
4
  fromEnum Ccy
BEF = Int
5
  fromEnum Ccy
BGL = Int
6
  fromEnum Ccy
BRL = Int
7
  fromEnum Ccy
BTC = Int
8
  fromEnum Ccy
BYR = Int
9
  fromEnum Ccy
CAD = Int
10
  fromEnum Ccy
CHF = Int
11
  fromEnum Ccy
CLP = Int
12
  fromEnum Ccy
CNY = Int
13
  fromEnum Ccy
COP = Int
14
  fromEnum Ccy
CYP = Int
15
  fromEnum Ccy
CZK = Int
16
  fromEnum Ccy
DASH = Int
17
  fromEnum Ccy
DEM = Int
18
  fromEnum Ccy
DKK = Int
19
  fromEnum Ccy
EEK = Int
20
  fromEnum Ccy
ESP = Int
21
  fromEnum Ccy
ETC = Int
22
  fromEnum Ccy
ETH = Int
23
  fromEnum Ccy
EUR = Int
24
  fromEnum Ccy
FIM = Int
25
  fromEnum Ccy
FRF = Int
26
  fromEnum Ccy
GBP = Int
27
  fromEnum Ccy
GRD = Int
28
  fromEnum Ccy
HKD = Int
29
  fromEnum Ccy
HUF = Int
30
  fromEnum Ccy
IDR = Int
31
  fromEnum Ccy
IEP = Int
32
  fromEnum Ccy
ILS = Int
33
  fromEnum Ccy
INR = Int
34
  fromEnum Ccy
IQD = Int
35
  fromEnum Ccy
IRR = Int
36
  fromEnum Ccy
ISK = Int
37
  fromEnum Ccy
ITL = Int
38
  fromEnum Ccy
JPY = Int
39
  fromEnum Ccy
KRW = Int
40
  fromEnum Ccy
KWD = Int
41
  fromEnum Ccy
KZT = Int
42
  fromEnum Ccy
LTC = Int
43
  fromEnum Ccy
LTL = Int
44
  fromEnum Ccy
LUF = Int
45
  fromEnum Ccy
LVL = Int
46
  fromEnum Ccy
MTL = Int
47
  fromEnum Ccy
MXN = Int
48
  fromEnum Ccy
MYR = Int
49
  fromEnum Ccy
NGN = Int
50
  fromEnum Ccy
NLG = Int
51
  fromEnum Ccy
NOK = Int
52
  fromEnum Ccy
NPR = Int
53
  fromEnum Ccy
NZD = Int
54
  fromEnum Ccy
PEH = Int
55
  fromEnum Ccy
PEI = Int
56
  fromEnum Ccy
PEN = Int
57
  fromEnum Ccy
PKR = Int
58
  fromEnum Ccy
PLN = Int
59
  fromEnum Ccy
PTE = Int
60
  fromEnum Ccy
ROL = Int
61
  fromEnum Ccy
RON = Int
62
  fromEnum Ccy
RUB = Int
63
  fromEnum Ccy
SAR = Int
64
  fromEnum Ccy
SEK = Int
65
  fromEnum Ccy
SGD = Int
66
  fromEnum Ccy
SIT = Int
67
  fromEnum Ccy
SKK = Int
68
  fromEnum Ccy
THB = Int
69
  fromEnum Ccy
TRL = Int
70
  fromEnum Ccy
TRY = Int
71
  fromEnum Ccy
TTD = Int
72
  fromEnum Ccy
TWD = Int
73
  fromEnum Ccy
UAH = Int
74
  fromEnum Ccy
USD = Int
75
  fromEnum Ccy
VEB = Int
76
  fromEnum Ccy
VND = Int
77
  fromEnum Ccy
XRP = Int
78
  fromEnum Ccy
ZAR = Int
79
  fromEnum Ccy
ZEC = Int
80
  fromEnum Ccy
AED = Int
81
  fromEnum Ccy
AOA = Int
82
  fromEnum Ccy
BGN = Int
83
  fromEnum Ccy
BHD = Int
84
  fromEnum Ccy
BWP = Int
85
  fromEnum Ccy
CLF = Int
86
  fromEnum Ccy
CNH = Int
87
  fromEnum Ccy
COU = Int
88
  fromEnum Ccy
EGP = Int
89
  fromEnum Ccy
ETB = Int
90
  fromEnum Ccy
GEL = Int
91
  fromEnum Ccy
GHS = Int
92
  fromEnum Ccy
HRK = Int
93
  fromEnum Ccy
JOD = Int
94
  fromEnum Ccy
KES = Int
95
  fromEnum Ccy
LKR = Int
96
  fromEnum Ccy
MAD = Int
97
  fromEnum Ccy
MKD = Int
98
  fromEnum Ccy
MUR = Int
99
  fromEnum Ccy
MXV = Int
100
  fromEnum Ccy
OMR = Int
101
  fromEnum Ccy
PHP = Int
102
  fromEnum Ccy
QAR = Int
103
  fromEnum Ccy
RSD = Int
104
  fromEnum Ccy
TND = Int
105
  fromEnum Ccy
UGX = Int
106
  fromEnum Ccy
UYU = Int
107
  fromEnum Ccy
UZS = Int
108
  fromEnum Ccy
XOF = Int
109
  fromEnum Ccy
ZMW = Int
110

  toEnum :: Int -> Ccy
toEnum Int
0 = Ccy
ARS
  toEnum Int
1 = Ccy
ATS
  toEnum Int
2 = Ccy
AUD
  toEnum Int
3 = Ccy
BCH
  toEnum Int
4 = Ccy
BDT
  toEnum Int
5 = Ccy
BEF
  toEnum Int
6 = Ccy
BGL
  toEnum Int
7 = Ccy
BRL
  toEnum Int
8 = Ccy
BTC
  toEnum Int
9 = Ccy
BYR
  toEnum Int
10 = Ccy
CAD
  toEnum Int
11 = Ccy
CHF
  toEnum Int
12 = Ccy
CLP
  toEnum Int
13 = Ccy
CNY
  toEnum Int
14 = Ccy
COP
  toEnum Int
15 = Ccy
CYP
  toEnum Int
16 = Ccy
CZK
  toEnum Int
17 = Ccy
DASH
  toEnum Int
18 = Ccy
DEM
  toEnum Int
19 = Ccy
DKK
  toEnum Int
20 = Ccy
EEK
  toEnum Int
21 = Ccy
ESP
  toEnum Int
22 = Ccy
ETC
  toEnum Int
23 = Ccy
ETH
  toEnum Int
24 = Ccy
EUR
  toEnum Int
25 = Ccy
FIM
  toEnum Int
26 = Ccy
FRF
  toEnum Int
27 = Ccy
GBP
  toEnum Int
28 = Ccy
GRD
  toEnum Int
29 = Ccy
HKD
  toEnum Int
30 = Ccy
HUF
  toEnum Int
31 = Ccy
IDR
  toEnum Int
32 = Ccy
IEP
  toEnum Int
33 = Ccy
ILS
  toEnum Int
34 = Ccy
INR
  toEnum Int
35 = Ccy
IQD
  toEnum Int
36 = Ccy
IRR
  toEnum Int
37 = Ccy
ISK
  toEnum Int
38 = Ccy
ITL
  toEnum Int
39 = Ccy
JPY
  toEnum Int
40 = Ccy
KRW
  toEnum Int
41 = Ccy
KWD
  toEnum Int
42 = Ccy
KZT
  toEnum Int
43 = Ccy
LTC
  toEnum Int
44 = Ccy
LTL
  toEnum Int
45 = Ccy
LUF
  toEnum Int
46 = Ccy
LVL
  toEnum Int
47 = Ccy
MTL
  toEnum Int
48 = Ccy
MXN
  toEnum Int
49 = Ccy
MYR
  toEnum Int
50 = Ccy
NGN
  toEnum Int
51 = Ccy
NLG
  toEnum Int
52 = Ccy
NOK
  toEnum Int
53 = Ccy
NPR
  toEnum Int
54 = Ccy
NZD
  toEnum Int
55 = Ccy
PEH
  toEnum Int
56 = Ccy
PEI
  toEnum Int
57 = Ccy
PEN
  toEnum Int
58 = Ccy
PKR
  toEnum Int
59 = Ccy
PLN
  toEnum Int
60 = Ccy
PTE
  toEnum Int
61 = Ccy
ROL
  toEnum Int
62 = Ccy
RON
  toEnum Int
63 = Ccy
RUB
  toEnum Int
64 = Ccy
SAR
  toEnum Int
65 = Ccy
SEK
  toEnum Int
66 = Ccy
SGD
  toEnum Int
67 = Ccy
SIT
  toEnum Int
68 = Ccy
SKK
  toEnum Int
69 = Ccy
THB
  toEnum Int
70 = Ccy
TRL
  toEnum Int
71 = Ccy
TRY
  toEnum Int
72 = Ccy
TTD
  toEnum Int
73 = Ccy
TWD
  toEnum Int
74 = Ccy
UAH
  toEnum Int
75 = Ccy
USD
  toEnum Int
76 = Ccy
VEB
  toEnum Int
77 = Ccy
VND
  toEnum Int
78 = Ccy
XRP
  toEnum Int
79 = Ccy
ZAR
  toEnum Int
80 = Ccy
ZEC
  toEnum Int
81 = Ccy
AED
  toEnum Int
82 = Ccy
AOA
  toEnum Int
83 = Ccy
BGN
  toEnum Int
84 = Ccy
BHD
  toEnum Int
85 = Ccy
BWP
  toEnum Int
86 = Ccy
CLF
  toEnum Int
87 = Ccy
CNH
  toEnum Int
88 = Ccy
COU
  toEnum Int
89 = Ccy
EGP
  toEnum Int
90 = Ccy
ETB
  toEnum Int
91 = Ccy
GEL
  toEnum Int
92 = Ccy
GHS
  toEnum Int
93 = Ccy
HRK
  toEnum Int
94 = Ccy
JOD
  toEnum Int
95 = Ccy
KES
  toEnum Int
96 = Ccy
LKR
  toEnum Int
97 = Ccy
MAD
  toEnum Int
98 = Ccy
MKD
  toEnum Int
99 = Ccy
MUR
  toEnum Int
100 = Ccy
MXV
  toEnum Int
101 = Ccy
OMR
  toEnum Int
102 = Ccy
PHP
  toEnum Int
103 = Ccy
QAR
  toEnum Int
104 = Ccy
RSD
  toEnum Int
105 = Ccy
TND
  toEnum Int
106 = Ccy
UGX
  toEnum Int
107 = Ccy
UYU
  toEnum Int
108 = Ccy
UZS
  toEnum Int
109 = Ccy
XOF
  toEnum Int
110 = Ccy
ZMW
  toEnum Int
unmatched = String -> Ccy
forall a. HasCallStack => String -> a
error (String
"Ccy.toEnum: Cannot match " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
unmatched)

{-# LINE 58 "./QuantLib/Currency.chs" #-}



{-# LINE 60 "./QuantLib/Currency.chs" #-}


{-# LINE 61 "./QuantLib/Currency.chs" #-}


{-# LINE 62 "./QuantLib/Currency.chs" #-}


-- |Look up one of the built-in ISO 4217 currencies by its enum tag.
currency :: (Ccy) -> IO ((Currency))
currency a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  preErrorCheck $ \a2' -> 
  currency'_ a1' a2' >>= \res ->
  peekCurrency res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 65 "./QuantLib/Currency.chs" #-}


-- |The currency's ISO 4217 three-letter code, e.g. \"USD\".
code :: Currency -> String
code x = unsafePerformIO $ mask_ (codeRaw x)
codeRaw :: (Currency) -> IO ((String))
codeRaw a1 =
  withCurrency a1 $ \a1' -> 
  codeRaw'_ a1' >>= \res ->
  peekDynString res >>= \res' ->
  return (res')

{-# LINE 70 "./QuantLib/Currency.chs" #-}


-- |The number of fractional units (e.g. cents) in one unit of the currency.
fractionsPerUnit :: (Currency) -> (Int)
fractionsPerUnit a1 =
  C2HSImp.unsafePerformIO $
  withCurrency a1 $ \a1' -> 
  fractionsPerUnit'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 73 "./QuantLib/Currency.chs" #-}


-- |The currency's fractional-unit symbol, e.g. \"¢\".
fractionSymbol :: (Currency) -> (String)
fractionSymbol a1 =
  C2HSImp.unsafePerformIO $
  withCurrency a1 $ \a1' -> 
  fractionSymbol'_ a1' >>= \res ->
  C2HSImp.peekCString res >>= \res' ->
  return (res')

{-# LINE 76 "./QuantLib/Currency.chs" #-}


-- |The currency's ISO 4217 numeric code, e.g. 840 for USD.
numericCode :: (Currency) -> (Int)
numericCode a1 =
  C2HSImp.unsafePerformIO $
  withCurrency a1 $ \a1' -> 
  numericCode'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 79 "./QuantLib/Currency.chs" #-}


-- |The currency's symbol, e.g. \"$\".
symbol :: (Currency) -> (String)
symbol a1 =
  C2HSImp.unsafePerformIO $
  withCurrency a1 $ \a1' -> 
  symbol'_ a1' >>= \res ->
  C2HSImp.peekCString res >>= \res' ->
  return (res')

{-# LINE 82 "./QuantLib/Currency.chs" #-}


-- |Construct a custom currency from its name, codes, symbols, rounding convention and an
-- optional triangulation currency used for indirect exchange.
customCurrency :: (String) -- ^name
 -> (String) -- ^code
 -> (Int) -- ^numericCode
 -> (String) -- ^symbol
 -> (String) -- ^fractionSymbol
 -> (Int) -- ^fractionsPerUnit
 -> (Maybe Rounding) -> (Maybe Currency) -- ^triangulationCurrency
 -> IO ((Currency))
customCurrency a1 a2 a3 a4 a5 a6 a7 a8 =
  C2HSImp.withCString a1 $ \a1' -> 
  C2HSImp.withCString a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  C2HSImp.withCString a4 $ \a4' -> 
  C2HSImp.withCString a5 $ \a5' -> 
  let {a6' = fromIntegral a6} in 
  withMaybeRounding a7 $ \a7' -> 
  withMaybeCurrency a8 $ \a8' -> 
  preErrorCheck $ \a9' -> 
  customCurrency'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' >>= \res ->
  peekCurrency res >>= \res' ->
  errorCheck  a9'>>
  return (res')

{-# LINE 94 "./QuantLib/Currency.chs" #-}


-- |Construct a Direct exchange rate: a unit of @source@ is worth @rate@ units of @target@.
exchangeRate :: (Currency) -- ^source
 -> (Currency) -- ^target
 -> (Double) -- ^rate
 -> IO ((ExchangeRate))
exchangeRate a1 a2 a3 =
  withCurrency a1 $ \a1' -> 
  withCurrency a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  preErrorCheck $ \a4' -> 
  exchangeRate'_ a1' a2' a3' a4' >>= \res ->
  peekExchangeRate res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 102 "./QuantLib/Currency.chs" #-}


-- |The rate itself: a unit of the source currency is worth this many units of the target.
rate :: (ExchangeRate) -> IO ((Double))
rate a1 =
  withExchangeRate a1 $ \a1' -> 
  rate'_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 105 "./QuantLib/Currency.chs" #-}


-- |Whether the rate was given directly or derived by chaining two other rates.
exchangeRateType :: (ExchangeRate) -> IO ((ExchangeRateType))
exchangeRateType a1 =
  withExchangeRate a1 $ \a1' -> 
  exchangeRateType'_ a1' >>= \res ->
  let {res' = (toEnum . fromIntegral) res} in
  return (res')

{-# LINE 108 "./QuantLib/Currency.chs" #-}


-- |Apply an exchange rate to a cash amount (a @(Double, Currency)@ pair, standing in for
-- QuantLib's @Money@), returning the converted amount as a pair in the other currency of the
-- rate. Throws if the given currency is on neither side of the rate.
exchange :: (ExchangeRate) -> ((Double, Currency)) -- ^amount
 -> IO ((Double), (Currency))
exchange a1 a2 =
  withExchangeRate a1 $ \a1' -> 
  withMoney a2 $ \(a2'1, a2'2) -> 
  alloca $ \a3' -> 
  preErrorCheck $ \a4' -> 
  exchange'_ a1' a2'1  a2'2 a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  peekCurrencyPtr  a3'>>= \a3'' -> 
  errorCheck  a4'>>
  return (res', a3'')

{-# LINE 118 "./QuantLib/Currency.chs" #-}


-- |Combine two exchange rates sharing a common currency into a derived rate between their
-- other two currencies. Throws if the rates don't share a common currency.
chainExchangeRate :: (ExchangeRate) -> (ExchangeRate) -> IO ((ExchangeRate))
chainExchangeRate a1 a2 =
  withExchangeRate a1 $ \a1' -> 
  withExchangeRate a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  chainExchangeRate'_ a1' a2' a3' >>= \res ->
  peekExchangeRate res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 125 "./QuantLib/Currency.chs" #-}


-- |Register an exchange rate with the global exchange-rate repository, valid between the given
-- dates (inclusive). Use 'minDate'/'maxDate' for an always-valid rate.
addExchangeRate :: (ExchangeRate) -> (Day) -> (Day) -> IO ()
addExchangeRate a1 a2 a3 =
  withExchangeRate a1 $ \a1' -> 
  withDay a2 $ \a2' -> 
  withDay a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  addExchangeRate'_ a1' a2' a3' a4' >>
  errorCheck  a4'>>
  return ()

{-# LINE 131 "./QuantLib/Currency.chs" #-}


-- |Look up a (possibly derived) exchange rate between two currencies at a given date (or the
-- current evaluation date if 'Nothing'). Throws if no rate can be found. Pre-populated with a
-- set of known historical rates even before any 'addExchangeRate' call.
lookupExchangeRate :: (Currency) -> (Currency) -> (Maybe Day) -> (ExchangeRateType) -> IO ((ExchangeRate))
lookupExchangeRate a1 a2 a3 a4 =
  withCurrency a1 $ \a1' -> 
  withCurrency a2 $ \a2' -> 
  withMaybeDay a3 $ \a3' -> 
  let {a4' = (fromIntegral . fromEnum) a4} in 
  preErrorCheck $ \a5' -> 
  lookupExchangeRate'_ a1' a2' a3' a4' a5' >>= \res ->
  peekExchangeRate res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 139 "./QuantLib/Currency.chs" #-}


-- |Reset the exchange-rate repository back to its built-in set of known historical rates,
-- discarding anything added via 'addExchangeRate'.
clearExchangeRates :: IO ()
clearExchangeRates =
  clearExchangeRates'_ >>
  return ()

{-# LINE 143 "./QuantLib/Currency.chs" #-}


-- |The global 'Money' arithmetic setting controlling how amounts in different currencies are
-- combined (no conversion, convert to the base currency, or convert automatically).
moneyConversionType :: IO ((MoneyConversionType))
moneyConversionType =
  moneyConversionType'_ >>= \res ->
  let {res' = (toEnum . fromIntegral) res} in
  return (res')

{-# LINE 147 "./QuantLib/Currency.chs" #-}


-- |Set the global 'Money' arithmetic conversion setting.
setMoneyConversionType :: (MoneyConversionType) -> IO ()
setMoneyConversionType a1 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  setMoneyConversionType'_ a1' >>
  return ()

{-# LINE 150 "./QuantLib/Currency.chs" #-}


-- |The global base currency used by 'MoneyConversionType' base-currency conversion, if set.
moneyBaseCurrency :: IO ((Maybe Currency))
moneyBaseCurrency =
  preErrorCheck $ \a1' -> 
  moneyBaseCurrency'_ a1' >>= \res ->
  peekMaybeCurrency res >>= \res' ->
  errorCheck  a1'>>
  return (res')

{-# LINE 153 "./QuantLib/Currency.chs" #-}


-- |Set the global base currency used by 'MoneyConversionType' base-currency conversion.
setMoneyBaseCurrency :: (Currency) -> IO ()
setMoneyBaseCurrency a1 =
  withCurrency a1 $ \a1' -> 
  setMoneyBaseCurrency'_ a1' >>
  return ()

{-# LINE 156 "./QuantLib/Currency.chs" #-}


-- |Convert a cash amount to the configured base currency (via 'setMoneyBaseCurrency'), using
-- 'lookupExchangeRate' and rounding the result per the target currency's convention. Throws if
-- no base currency is set or no rate path exists.
convertToBaseCurrency :: ((Double, Currency)) -- ^amount
 -> IO ((Double), (Currency))
convertToBaseCurrency a1 =
  withMoney a1 $ \(a1'1, a1'2) -> 
  alloca $ \a2' -> 
  preErrorCheck $ \a3' -> 
  convertToBaseCurrency'_ a1'1  a1'2 a2' a3' >>= \res ->
  let {res' = realToFrac res} in
  peekCurrencyPtr  a2'>>= \a2'' -> 
  errorCheck  a3'>>
  return (res', a2'')

{-# LINE 165 "./QuantLib/Currency.chs" #-}


-- vim: set ff=unix ts=8 sts=2 sw=2 et:

foreign import ccall safe "QuantLib/Currency.chs.h qlCurrency"
  currency'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCurrency)))))

foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyCode"
  codeRaw'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyFractionsPerUnit"
  fractionsPerUnit'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO C2HSImp.CInt))

foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyFractionSymbol"
  fractionSymbol'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencyNumericCode"
  numericCode'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO C2HSImp.CInt))

foreign import ccall safe "QuantLib/Currency.chs.h qlCurrencySymbol"
  symbol'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

foreign import ccall safe "QuantLib/Currency.chs.h qlCreateCurrency"
  customCurrency'_ :: ((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 ())) -> (IO (C2HSImp.Ptr (CCurrency))))))))))))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRate"
  exchangeRate'_ :: ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CExchangeRate)))))))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateRate"
  rate'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (IO C2HSImp.CDouble))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateType_"
  exchangeRateType'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (IO C2HSImp.CInt))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateExchange"
  exchange'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CCurrency))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble))))))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateChain"
  chainExchangeRate'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> ((C2HSImp.Ptr (CExchangeRate)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CExchangeRate))))))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateManagerAdd"
  addExchangeRate'_ :: ((C2HSImp.Ptr (CExchangeRate)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateManagerLookup"
  lookupExchangeRate'_ :: ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (CCurrency)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CExchangeRate))))))))

foreign import ccall safe "QuantLib/Currency.chs.h qlExchangeRateManagerClear"
  clearExchangeRates'_ :: (IO ())

foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsConversionType"
  moneyConversionType'_ :: (IO C2HSImp.CInt)

foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsSetConversionType"
  setMoneyConversionType'_ :: (C2HSImp.CInt -> (IO ()))

foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsBaseCurrency"
  moneyBaseCurrency'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CCurrency))))

foreign import ccall safe "QuantLib/Currency.chs.h qlMoneySettingsSetBaseCurrency"
  setMoneyBaseCurrency'_ :: ((C2HSImp.Ptr (CCurrency)) -> (IO ()))

foreign import ccall safe "QuantLib/Currency.chs.h qlConvertToBaseCurrency"
  convertToBaseCurrency'_ :: (C2HSImp.CDouble -> ((C2HSImp.Ptr (CCurrency)) -> ((C2HSImp.Ptr (C2HSImp.Ptr (CCurrency))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))