aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/world/money/currency.lux
blob: 9b4abccdaeeb4de235a8ecbfdbad66beef55b794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
... https://en.wikipedia.org/wiki/Currency
(.require
 [library
  [lux (.except type all try)
   [abstract
    ["[0]" equivalence (.only Equivalence)]
    [monad (.only do)]]
   [control
    ["?" parser]]
   [data
    ["[0]" product]
    ["[0]" text]]
   [math
    [number
     ["n" nat]]]
   ["[0]" meta (.only)
    ["[0]" macro (.only)
     [syntax (.only syntax)]]
    ["[0]" code
     ["?[1]" \\parser]]
    ["[0]" type (.only)
     ["?[1]" \\parser]
     ["[0]" nominal]]]]])

(nominal.def .public (Currency of)
  (Record
   [#alphabetic_code Text
    #numeric_code Nat
    #subdivisions Nat])

  (def .public (currency [alphabetic_code numeric_code subdivisions])
    (Ex (_ of)
      (-> [Text Nat Nat]
          (Currency of)))
    (nominal.abstraction
     [#alphabetic_code alphabetic_code
      #numeric_code numeric_code
      #subdivisions subdivisions]))

  (with_template [<name> <slot> <type>]
    [(def .public <name>
       (All (_ of)
         (-> (Currency of)
             <type>))
       (|>> nominal.representation
            (the <slot>)))]

    [alphabetic_code #alphabetic_code Text]
    [numeric_code #numeric_code Nat]
    [subdivisions #subdivisions Nat]
    )

  (def .public equivalence
    (Equivalence (Currency Any))
    (at equivalence.functor each
        (|>> nominal.representation)
        (.all product.equivalence
              text.equivalence
              n.equivalence
              n.equivalence
              )))
  )

(def .public type
  (syntax (_ [it ?code.any])
    (macro.with_symbols ['_ 'of]
      (do meta.monad
        [it (meta.eval Type (` (.type_of ((is (All ((, '_) (, 'of))
                                                (-> (..Currency (, 'of))
                                                    (..Currency (, 'of))))
                                              (|>>))
                                          (, it)))))
         of (|> (as Type it)
                (?type.result (?type.applied (?.after (?type.exactly ..Currency)
                                                      ?type.any)))
                meta.of_try)]
        (in (list (type.code of)))))))

(def (power parameter subject)
  (-> Nat Nat
      Nat)
  (when parameter
    0 1
    _ (|> subject
          (power (-- parameter))
          (n.* subject))))

... https://en.wikipedia.org/wiki/ISO_4217
(with_template [<short> <type> <alphabetic_code> <numeric_code> <decimals> <long>]
  [(def .public <short>
     (..currency [<alphabetic_code>
                  <numeric_code>
                  (power <decimals> 10)]))

   (def .public <type>
     Type
     (let [[module short] (symbol .._)]
       {.#Named [module <alphabetic_code>]
                (..type <short>)}))

   (def .public <long>
     (Currency <type>)
     <short>)]

  [aed AED "AED" 784 2 united_arab_emirates_dirham]
  [afn AFN "AFN" 971 2 afghan_afghani]
  [all ALL "ALL" 008 2 albanian_lek]
  [amd AMD "AMD" 051 2 armenian_dram]
  [ang ANG "ANG" 532 2 netherlands_antillean_guilder]
  [aoa AOA "AOA" 973 2 angolan_kwanza]
  [ars ARS "ARS" 032 2 argentine_peso]
  [aud AUD "AUD" 036 2 australian_dollar]
  [awg AWG "AWG" 533 2 aruban_florin]
  [azn AZN "AZN" 944 2 azerbaijani_manat]
  [bam BAM "BAM" 977 2 bosnia_and_herzegovina_convertible_mark]

  [bbd BBD "BBD" 052 2 barbados_dollar]
  [bdt BDT "BDT" 050 2 bangladeshi_taka]
  [bgn BGN "BGN" 975 2 bulgarian_lev]
  [bhd BHD "BHD" 048 3 bahraini_dinar]
  [bif BIF "BIF" 108 0 burundian_franc]
  [bmd BMD "BMD" 060 2 bermudian_dollar]
  [bnd BND "BND" 096 2 brunei_dollar]
  [bob BOB "BOB" 068 2 boliviano]
  [brl BRL "BRL" 986 2 brazilian_real]
  [bsd BSD "BSD" 044 2 bahamian_dollar]
  [btn BTN "BTN" 064 2 bhutanese_ngultrum]
  [bwp BWP "BWP" 072 2 botswana_pula]
  [byn BYN "BYN" 933 2 belarusian_ruble]
  [bzd BZD "BZD" 084 2 belize_dollar]

  [cad CAD "CAD" 124 2 canadian_dollar]
  [cdf CDF "CDF" 976 2 congolese_franc]
  [chf CHF "CHF" 756 2 swiss_franc]
  [clp CLP "CLP" 152 0 chilean_peso]
  [cop COP "COP" 170 2 colombian_peso]
  [crc CRC "CRC" 188 2 costa_rican_colon]
  [cuc CUC "CUC" 931 2 cuban_convertible_peso]
  [cup CUP "CUP" 192 2 cuban_peso]
  [cve CVE "CVE" 132 2 cape_verdean_escudo]
  [czk CZK "CZK" 203 2 czech_koruna]

  [djf DJF "DJF" 262 0 djiboutian_franc]
  [dkk DKK "DKK" 208 2 danish_krone]
  [dop DOP "DOP" 214 2 dominican_peso]
  [dzd DZD "DZD" 012 2 algerian_dinar]
  
  [egp EGP "EGP" 818 2 egyptian_pound]
  [ern ERN "ERN" 232 2 eritrean_nakfa]
  [etb ETB "ETB" 230 2 ethiopian_birr]
  [eur EUR "EUR" 978 2 euro]

  [fjd FJD "FJD" 242 2 fiji_dollar]
  [fkp FKP "FKP" 238 2 falkland_islands_pound]

  [gbp GBP "GBP" 826 2 pound_sterling]
  [gel GEL "GEL" 981 2 georgian_lari]
  [ghs GHS "GHS" 936 2 ghanaian_cedi]
  [gip GIP "GIP" 292 2 gibraltar_pound]
  [gmd GMD "GMD" 270 2 gambian_dalasi]
  [gnf GNF "GNF" 324 0 guinean_franc]
  [gtq GTQ "GTQ" 320 2 guatemalan_quetzal]
  [gyd GYD "GYD" 328 2 guyanese_dollar]

  [hkd HKD "HKD" 344 2 hong_kong_dollar]
  [hnl HNL "HNL" 340 2 honduran_lempira]
  [hrk HRK "HRK" 191 2 croatian_kuna]
  [htg HTG "HTG" 332 2 haitian_gourde]
  [huf HUF "HUF" 348 2 hungarian_forint]

  [idr IDR "IDR" 360 2 indonesian_rupiah]
  [ils ILS "ILS" 376 2 israeli_new_shekel]
  [inr INR "INR" 356 2 indian_rupee]
  [iqd IQD "IQD" 368 3 iraqi_dinar]
  [irr IRR "IRR" 364 2 iranian_rial]
  [isk ISK "ISK" 352 0 icelandic_krona]

  [jmd JMD "JMD" 388 2 jamaican_dollar]
  [jod JOD "JOD" 400 3 jordanian_dinar]
  [jpy JPY "JPY" 392 0 japanese_yen]

  [kes KES "KES" 404 2 kenyan_shilling]
  [kgs KGS "KGS" 417 2 kyrgyzstani_som]
  [khr KHR "KHR" 116 2 cambodian_riel]
  [kmf KMF "KMF" 174 0 comoro_franc]
  [kpw KPW "KPW" 408 2 north_korean_won]
  [krw KRW "KRW" 410 0 south_korean_won]
  [kwd KWD "KWD" 414 3 kuwaiti_dinar]
  [kyd KYD "KYD" 136 2 cayman_islands_dollar]
  [kzt KZT "KZT" 398 2 kazakhstani_tenge]

  [lak LAK "LAK" 418 2 lao_kip]
  [lbp LBP "LBP" 422 2 lebanese_pound]
  [lkr LKR "LKR" 144 2 sri_lankan_rupee]
  [lrd LRD "LRD" 430 2 liberian_dollar]
  [lsl LSL "LSL" 426 2 lesotho_loti]
  [lyd LYD "LYD" 434 3 libyan_dinar]

  [mad MAD "MAD" 504 2 moroccan_dirham]
  [mdl MDL "MDL" 498 2 moldovan_leu]
  [mga MGA "MGA" 969 2 malagasy_ariary]
  [mkd MKD "MKD" 807 2 macedonian_denar]
  [mmk MMK "MMK" 104 2 myanmar_kyat]
  [mnt MNT "MNT" 496 2 mongolian_togrog]
  [mop MOP "MOP" 446 2 macanese_pataca]
  [mru MRU "MRU" 929 2 mauritanian_ouguiya]
  [mur MUR "MUR" 480 2 mauritian_rupee]
  [mvr MVR "MVR" 462 2 maldivian_rufiyaa]
  [mwk MWK "MWK" 454 2 malawian_kwacha]
  [mxn MXN "MXN" 484 2 mexican_peso]
  [myr MYR "MYR" 458 2 malaysian_ringgit]
  [mzn MZN "MZN" 943 2 mozambican_metical]

  [nad NAD "NAD" 516 2 namibian_dollar]
  [ngn NGN "NGN" 566 2 nigerian_naira]
  [nio NIO "NIO" 558 2 nicaraguan_cordoba]
  [nok NOK "NOK" 578 2 norwegian_krone]
  [npr NPR "NPR" 524 2 nepalese_rupee]
  [nzd NZD "NZD" 554 2 new_zealand_dollar]

  [omr OMR "OMR" 512 3 omani_rial]

  [pab PAB "PAB" 590 2 panamanian_balboa]
  [pen PEN "PEN" 604 2 peruvian_sol]
  [pgk PGK "PGK" 598 2 papua_new_guinean_kina]
  [php PHP "PHP" 608 2 philippine_peso]
  [pkr PKR "PKR" 586 2 pakistani_rupee]
  [pln PLN "PLN" 985 2 polish_ztoty]
  [pyg PYG "PYG" 600 0 paraguayan_guarani]

  [qar QAR "QAR" 634 2 qatari_riyal]

  [ron RON "RON" 946 2 romanian_leu]
  [rsd RSD "RSD" 941 2 serbian_dinar]
  [cny CNY "CNY" 156 2 renminbi]
  [rub RUB "RUB" 643 2 russian_ruble]
  [rwf RWF "RWF" 646 0 rwandan_franc]

  [sar SAR "SAR" 682 2 saudi_riyal]
  [sbd SBD "SBD" 090 2 solomon_islands_dollar]
  [scr SCR "SCR" 690 2 seychelles_rupee]
  [sdg SDG "SDG" 938 2 sudanese_pound]
  [sek SEK "SEK" 752 2 swedish_krona]
  [sgd SGD "SGD" 702 2 singapore_dollar]
  [shp SHP "SHP" 654 2 saint_helena_pound]
  [sos SOS "SOS" 706 2 somali_shilling]
  [srd SRD "SRD" 968 2 surinamese_dollar]
  [ssp SSP "SSP" 728 2 south_sudanese_pound]
  [stn STN "STN" 930 2 sao_tome_and_principe_dobra]
  [svc SVC "SVC" 222 2 salvadoran_colon]
  [syp SYP "SYP" 760 2 syrian_pound]
  [szl SZL "SZL" 748 2 swazi_lilangeni]

  [thb THB "THB" 764 2 thai_baht]
  [tjs TJS "TJS" 972 2 tajikistani_somoni]
  [tmt TMT "TMT" 934 2 turkmenistan_manat]
  [tnd TND "TND" 788 3 tunisian_dinar]
  [top TOP "TOP" 776 2 tongan_pa'anga]
  [try TRY "TRY" 949 2 turkish_lira]
  [ttd TTD "TTD" 780 2 trinidad_and_tobago_dollar]
  [twd TWD "TWD" 901 2 new_taiwan_dollar]
  [tzs TZS "TZS" 834 2 tanzanian_shilling]
  
  [uah UAH "UAH" 980 2 ukrainian_hryvnia]
  [ugx UGX "UGX" 800 0 ugandan_shilling]
  [usd USD "USD" 840 2 united_states_dollar]
  [uyu UYU "UYU" 858 2 uruguayan_peso]
  [uzs UZS "UZS" 860 2 uzbekistan_sum]
  [ves VES "VES" 928 2 venezuelan_sovereign_bolivar]
  [vnd VND "VND" 704 0 vietnamese_dong]
  [vuv VUV "VUV" 548 0 vanuatu_vatu]
  [wst WST "WST" 882 2 samoan_tala]
  
  [xag XAG "XAG" 961 0 silver]
  [xau XAU "XAU" 959 0 gold]
  [xcd XCD "XCD" 951 2 east_caribbean_dollar]
  [xpd XPD "XPD" 964 0 palladium]
  [xpt XPT "XPT" 962 0 platinum]

  [zar ZAR "ZAR" 710 2 south_african_rand]
  [zmw ZMW "ZMW" 967 2 zambian_kwacha]
  [zwl ZWL "ZWL" 932 2 zimbabwean_dollar]
  )