Facts (empty) → 0.1
raw patch · 16 files changed
+2069/−0 lines, 16 filesdep +AC-Angledep +QuickCheckdep +basesetup-changed
Dependencies added: AC-Angle, QuickCheck, base, containers, digits, template-haskell
Files
- Facts.cabal +51/−0
- LICENSE +24/−0
- Setup.hs +2/−0
- src/Data/Numerals/Decimal.hs +64/−0
- src/Facts/Geography/Continents.hs +26/−0
- src/Facts/Geography/Countries.hs +123/−0
- src/Facts/Geography/Countries/Internal/Data.hs +1341/−0
- src/Facts/Geography/Countries/Internal/Splices.hs +39/−0
- src/Facts/Geography/Countries/UnitedStates.hs +98/−0
- src/Facts/Geography/Countries/UnitedStates/Address.hs +24/−0
- src/Facts/Geography/Countries/UnitedStates/Internal/Data.hs +111/−0
- src/Facts/Geography/Countries/UnitedStates/Internal/Splices.hs +12/−0
- src/Facts/Geography/Countries/UnitedStates/ZipCode.hs +21/−0
- src/Facts/Geography/Location.hs +61/−0
- src/Facts/Utility/OrphanInstances.hs +20/−0
- src/Facts/Utility/Templates.hs +52/−0
+ Facts.cabal view
@@ -0,0 +1,51 @@+cabal-version: >= 1.6+name: Facts+version: 0.1++copyright: © 2010 2piix.com+license: BSD3+license-file: LICENSE+synopsis: A collection of facts about the real world.+category: Factual+author: Alexander Solla+maintainer: ajs@2piix.com+++description:+ The Facts hierarchy is meant to contain commonly used, relatively static facts about the \"real world\". The facts are meant to be encoded using relatively simple Haskell constructs. However, we do make some promises: every data type our modules export will have instances of 'Data', 'Eq', 'Ord', 'Show', and'Typeable'. We will use explicit module export lists to control access to internal data structures.+ .+ As much of the data we are encoding is tabular, we use simple structures like lists and maps to encode the relations. This has two practical ramifications: the textual representation of the data can be very wide, but are also very easy to edit, with \"block editing\" tools like Vi's visual block mode. The other consequence is that the naive approach to writing queries can be tedious, and the resulting naive queries are slower than they could be. Template Haskell can eliminate much of this drudgery. Felipe Lessa has graciously donated some Template Haskell code which we have adapted.+ .+ The Facts\.\* hierarchy currently contains modules with geographical information, such as a data type of countries, cross references to various ISO-3166-1 names for each, a list of states in the United States, and the United States address format. Please see the module hierarchy for more specifics. Patches are welcomed, though prospective contributors are encouraged to encode data structures using lists of pairs to encode bijections, all exposed data types are instances of 'Data', `Eq`, `Ord`, `Show`, and `Typeable`, and using explicit exports to only export queries and their input and output types and constructors. For now, we will add facts to the hierarchy lazily, as our projects need them.++tested-with: GHC ==6.12.1+build-type: Simple+source-repository head+ type: darcs+ location: http://code.haskell.org/Facts/+++Library+ build-depends: base >4 && <5+ , AC-Angle ==1.0+ , containers ==0.3.*+ , digits ==0.2.*+ , template-haskell ==2.4.*+ , QuickCheck ==2.1.*++ hs-source-dirs: src++ exposed-modules: Facts.Geography.Continents+ Facts.Geography.Countries+ Facts.Geography.Countries.UnitedStates+ Facts.Geography.Countries.UnitedStates.Address+ Facts.Geography.Countries.UnitedStates.ZipCode+ Facts.Geography.Location++ other-modules: Data.Numerals.Decimal+ Facts.Geography.Countries.Internal.Data+ Facts.Geography.Countries.Internal.Splices+ Facts.Geography.Countries.UnitedStates.Internal.Data+ Facts.Geography.Countries.UnitedStates.Internal.Splices+ Facts.Utility.OrphanInstances+ Facts.Utility.Templates
+ LICENSE view
@@ -0,0 +1,24 @@+Copyright (c) 2010 2piix.com+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:+ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+ * Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+ * Neither the name 2piix.com nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Numerals/Decimal.hs view
@@ -0,0 +1,64 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++module Data.Numerals.Decimal where+++import Data.Data+import Data.Digits+import Data.Typeable+import Test.QuickCheck+import Test.QuickCheck.Gen+++data DecimalDigit = Zero | One | Two | Three | Four | Five | Six | Seven | Eight | Nine+ deriving (Data, Enum, Eq, Ord, Typeable)++instance Show DecimalDigit where show = show . fromEnum++-- | Takes a DecimalDigit to its Integral form+decimal_digit_to_integral :: (Integral n) => DecimalDigit -> n+decimal_digit_to_integral digit = case digit of + Zero -> 0+ One -> 1+ Two -> 2+ Three -> 3+ Four -> 4+ Five -> 5+ Six -> 6+ Seven -> 7+ Eight -> 8+ Nine -> 9+ +-- | Takes an Integral digit to a DecimalDigit. This function is partial+-- on a set of Integrals.+unsafe_integral_digit_to_decimal_digit :: (Integral n) => n -> DecimalDigit+unsafe_integral_digit_to_decimal_digit integer = case integer of+ 0 -> Zero + 1 -> One + 2 -> Two + 3 -> Three + 4 -> Four + 5 -> Five + 6 -> Six + 7 -> Seven + 8 -> Eight + 9 -> Nine + + ++integral_to_digits :: (Integral n) => n -> [DecimalDigit]+integral_to_digits = (fmap unsafe_integral_digit_to_decimal_digit) . (digits 10)++digits_to_integral :: (Integral n) => [DecimalDigit] -> n+digits_to_integral = (unDigits 10) . (fmap decimal_digit_to_integral)++++prop_decimal_digit_round_trip :: [DecimalDigit] -> Bool+prop_decimal_digit_round_trip d = (integral_to_digits . digits_to_integral $ d) == d++prop_positive_integral_round_trip :: Integral n => n -> Bool+prop_positive_integral_round_trip n = (digits_to_integral . integral_to_digits . abs $ n) == abs n
+ src/Facts/Geography/Continents.hs view
@@ -0,0 +1,26 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-} +{-# LANGUAGE DeriveDataTypeable #-}++module Facts.Geography.Continents where++import Data.Data+import Data.Typeable++data Continent = Africa+ | Antarctica+ | Asia+ | Australia+ | Europe+ | NorthAmerica+ | SouthAmerica+ deriving (Data, Eq, Ord, Typeable)++instance Show Continent where+ show Africa = "Africa" + show Antarctica = "Antarctica"+ show Asia = "Asia"+ show Australia = "Australia"+ show Europe = "Europe"+ show NorthAmerica = "North America"+ show SouthAmerica = "South America"
+ src/Facts/Geography/Countries.hs view
@@ -0,0 +1,123 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE ViewPatterns #-}++module Facts.Geography.Countries ( Country (..) --+ , ISOAlpha2Code (..)+ , ISOAlpha3Code (..)+ , ISONumericCode+ , UNFormalName+ , UNShortName+ , isoNumericCode+ , shortEnglishCountryName+ , formalEnglishCountryName + , isoAlpha2Code_for_country + , isoAlpha3Code_for_country + , country_for_isoAlpha2Code + , country_for_isoAlpha3Code+ , isoNumericCode_for_country + , country_for_valid_isoNumericCode+ , country_for_isoNumericCode+ ) where ++import Data.Numerals.Decimal++import Facts.Geography.Countries.Internal.Splices+import Facts.Geography.Countries.Internal.Data++import Test.QuickCheck+import Test.QuickCheck.Gen+++instance Show Country where+ show = shortEnglishCountryName++++-- | Maps a 'Country' to its ISO-3166-1 2-character code.+isoAlpha2Code_for_country :: Country -> ISOAlpha2Code++-- | Maps a 'Country' to its ISO-3166-1 3-character code.+isoAlpha3Code_for_country :: Country -> ISOAlpha3Code++-- | Maps a 'Country' to its ISO-3166-1 numeric code.+isoNumericCode_for_country :: Country -> ISONumericCode++-- | Maps an ISO-3166-1 2-character code to a 'Country'.+country_for_isoAlpha2Code :: ISOAlpha2Code -> Country++-- | Maps an ISO-3166-1 3-character code to a 'Country'.+country_for_isoAlpha3Code :: ISOAlpha3Code -> Country+++country_code_by_country = _country_code_by_country+country_by_country_code = _country_by_country_code+country_name_by_country = _country_name_by_country ++++isoAlpha2Code_for_country = _isoAlpha2_for_country+isoAlpha3Code_for_country = _isoAlpha3_for_country+isoNumericCode_for_country = _isoNumeric_for_country+ + +country_for_isoAlpha2Code = _country_for_isoAlpha2+country_for_isoAlpha3Code = _country_for_isoAlpha3+++++ +++-- | The ISO Numeric Code space is not fully packed. Many codes are \"reserved\" or otherwise+-- unused. 'country_for_isoNumericCode' takes an 'ISONumericCode' and possibly returns a matching+-- 'Country'. +country_for_isoNumericCode :: ISONumericCode -> Maybe Country+country_for_isoNumericCode = (fmap country_for_valid_isoNumericCode) . validate_isoNumericCode+++-- | 'country_for_valid_isoNumericCode' maps a valid 'ISONumericCode' to a 'Country'. Unfortunately,+-- this is a partial function. Use 'country_for_isoNumericCode' instead, unless you can guarantee+-- that the 'ISONumericCode' supplied to the query is valid.+country_for_valid_isoNumericCode :: ISONumericCode -> Country+country_for_valid_isoNumericCode = _country_for_isoNumeric +++-- | 'shortEnglishCountryName' maps a Country to an ISO-3166-1 \"short name\". By the international+-- standard, these names are taken from the \"United Nations Terminology Bulletin Country Names\",+-- and \"Country and Region Codes for Statistical Use\" of the UN Statistics Division. ++shortEnglishCountryName :: Country -> UNShortName+shortEnglishCountryName = _shortEnglishCountryName+++-- | 'formalEnglishCountryName' maps a Country to an ISO-3166-1 \"formal name\". By the international+-- standard, these names are taken from the \"United Nations Terminology Bulletin Country Names\",+-- and \"Country and Region Codes for Statistical Use\" of the UN Statistics Division. ++formalEnglishCountryName :: Country -> UNFormalName+formalEnglishCountryName = _formalEnglishCountryName +++ + ++instance Arbitrary Country where arbitrary = elements [Afghanistan .. Zimbabwe]++newtype ValidCode = ValidCode ISOCountryCode deriving (Show)+instance Arbitrary ValidCode where arbitrary = elements . fmap (ValidCode) $ valid_iso_country_codes++prop_country_to_code_roundtrip :: Country -> Bool+prop_country_to_code_roundtrip country = (country_by_country_code . country_code_by_country $ country) == country++prop_code_to_country_roundtrip :: ValidCode -> Bool+prop_code_to_country_roundtrip (ValidCode code) = (country_code_by_country . country_by_country_code $ code) == code ++++
+ src/Facts/Geography/Countries/Internal/Data.hs view
@@ -0,0 +1,1341 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-}+{-# LANGUAGE DeriveDataTypeable #-}++module Facts.Geography.Countries.Internal.Data ( Country (..)+ , CountryName (..)+ , ISOAlpha2Code (..)+ , ISOAlpha3Code (..)+ , ISOCountryCode (..)+ , ISONumericCode (..)+ , isoNumericCode+ , countries_and_united_nations_names+ , countries_and_iso_country_codes+ , UNFormalName+ , UNShortName+ , valid_iso_country_codes+ , valid_iso_numeric_codes+ , validate_isoNumericCode+ ) where++import Data.Data+import Data.Maybe+import Data.Numerals.Decimal+import Data.Typeable++import Prelude hiding (GT, LT)++import Facts.Utility.Templates+++-- | The type of \"countries\" includes sovereign nations and other \"areas of geographical interest\",+-- as defined by the United Nations, whose definition was adopted by ISO.++data Country = Afghanistan+ | AlandIslands+ | Albania+ | Algeria+ | AmericanSamoa+ | Andorra+ | Angola+ | Anguilla+ | Antarctica+ | AntiguaAndBarbuda+ | Argentina+ | Armenia+ | Aruba+ | Australia+ | Austria+ | Azerbaijan+ | Bahamas+ | Bahrain+ | Bangladesh+ | Barbados+ | Belarus+ | Belgium+ | Belize+ | Benin+ | Bermuda+ | Bhutan+ | Bolivia+ | BosniaAndHerzegovina+ | Botswana+ | BouvetIsland+ | Brazil+ | BritishIndianOceanTerritory+ | BruneiDarussalam+ | Bulgaria+ | BurkinaFaso+ | Burundi+ | Cambodia+ | Cameroon+ | Canada+ | CapeVerde+ | CaymanIslands+ | CentralAfricanRepublic+ | Chad+ | Chile+ | China+ | ChristmasIsland+ | CocosKeelingIslands+ | Colombia+ | Comoros+ | Congo+ | DemocraticRepublicOfCongo+ | CookIslands+ | CostaRica+ | CoteDIvoire+ | Croatia+ | Cuba+ | Cyprus+ | CzechRepublic+ | Denmark+ | Djibouti+ | Dominica+ | DominicanRepublic+ | Ecuador+ | Egypt+ | ElSalvador+ | EquatorialGuinea+ | Eritrea+ | Estonia+ | Ethiopia+ | FalklandIslands+ | FaroeIslands+ | Fiji+ | Finland+ | France+ | FrenchGuiana+ | FrenchPolynesia+ | FrenchSouthernTerritories+ | Gabon+ | Gambia+ | Georgia+ | Germany+ | Ghana+ | Gibraltar+ | Greece+ | Greenland+ | Grenada+ | Guadeloupe+ | Guam+ | Guatemala+ | Guernsey+ | Guinea+ | GuineaBissau+ | Guyana+ | Haiti+ | HeardIslandAndMcDonaldIslands+ | HolySee+ | Honduras+ | HongKong+ | Hungary+ | Iceland+ | India+ | Indonesia+ | Iran+ | Iraq+ | Ireland+ | IsleOfMan+ | Israel+ | Italy+ | Jamaica+ | Japan+ | Jersey+ | Jordan+ | Kazakhstan+ | Kenya+ | Kiribati+ | NorthKorea+ | SouthKorea+ | Kuwait+ | Kyrgyzstan+ | Laos+ | Latvia+ | Lebanon+ | Lesotho+ | Liberia+ | Libya+ | Liechtenstein+ | Lithuania+ | Luxembourg+ | Macao+ | Macedonia+ | Madagascar+ | Malawi+ | Malaysia+ | Maldives+ | Mali+ | Malta+ | MarshallIslands+ | Martinique+ | Mauritania+ | Mauritius+ | Mayotte+ | Mexico+ | Micronesia+ | Moldova+ | Monaco+ | Mongolia+ | Montenegro+ | Montserrat+ | Morocco+ | Mozambique+ | Myanmar+ | Namibia+ | Nauru+ | Nepal+ | Netherlands+ | NetherlandsAntilles+ | NewCaledonia+ | NewZealand+ | Nicaragua+ | Niger+ | Nigeria+ | Niue+ | NorfolkIsland+ | NorthernMarianaIslands+ | Norway+ | Oman+ | Pakistan+ | Palau+ | Palestinine+ | Panama+ | PapuaNewGuinea+ | Paraguay+ | Peru+ | Philippines+ | Pitcairn+ | Poland+ | Portugal+ | PuertoRico+ | Qatar+ | Reunion+ | Romania+ | RussianFederation+ | Rwanda+ | SaintBarthelemy+ | SaintHelenaAscensionAndTristanDaCunha+ | SaintKittsAndNevis+ | SaintLucia+ | SaintMartin+ | SaintPierreAndMiquelon+ | SaintVincentAndTheGrenadines+ | Samoa+ | SanMarino+ | SaoTomeAndPrincipe+ | SaudiArabia+ | Senegal+ | Serbia+ | Seychelles+ | SierraLeone+ | Singapore+ | Slovakia+ | Slovenia+ | SolomonIslands+ | Somalia+ | SouthAfrica+ | SouthGeorgiaAndtheSouthSandwichIslands+ | Spain+ | SriLanka+ | Sudan+ | Suriname+ | SvalbardAndJanMayen+ | Swaziland+ | Sweden+ | Switzerland+ | Syria+ | Taiwan+ | Tajikistan+ | Tanzania+ | Thailand+ | TimorLeste+ | Togo+ | Tokelau+ | Tonga+ | TrinidadAndTobago+ | Tunisia+ | Turkey+ | Turkmenistan+ | TurksAndCaicosIslands+ | Tuvalu+ | Uganda+ | Ukraine+ | UnitedArabEmirates+ | UnitedKingdom+ | UnitedStates+ | UnitedStatesMinorOutlyingIslands+ | Uruguay+ | Uzbekistan+ | Vanuatu+ | Venezuela+ | VietNam+ | BritishVirginIslands+ | USVirginIslands+ | WallisAndFutuna+ | WesternSahara+ | Yemen+ | Zambia+ | Zimbabwe+ deriving (Data, Enum, Eq, Ord, Typeable)++data ISOAlpha2Code = AF+ | AX+ | AL+ | DZ+ | AS+ | AD+ | AO+ | AI+ | AQ+ | AG+ | AR+ | AM+ | AW+ | AU+ | AT+ | AZ+ | BS+ | BH+ | BD+ | BB+ | BY+ | BE+ | BZ+ | BJ+ | BM+ | BT+ | BO+ | BA+ | BW+ | BV+ | BR+ | IO+ | BN+ | BG+ | BF+ | BI+ | KH+ | CM+ | CA+ | CV+ | KY+ | CF+ | TD+ | CL+ | CN+ | CX+ | CC+ | CO+ | KM+ | CG+ | CD+ | CK+ | CR+ | CI+ | HR+ | CU+ | CY+ | CZ+ | DK+ | DJ+ | DM+ | DO+ | EC+ | EG+ | SV+ | GQ+ | ER+ | EE+ | ET+ | FK+ | FO+ | FJ+ | FI+ | FR+ | GF+ | PF+ | TF+ | GA+ | GM+ | GE+ | DE+ | GH+ | GI+ | GR+ | GL+ | GD+ | GP+ | GU+ | GT+ | GG+ | GN+ | GW+ | GY+ | HT+ | HM+ | VA+ | HN+ | HK+ | HU+ | IS+ | IN+ | ID+ | IR+ | IQ+ | IE+ | IM+ | IL+ | IT+ | JM+ | JP+ | JE+ | JO+ | KZ+ | KE+ | KI+ | KP+ | KR+ | KW+ | KG+ | LA+ | LV+ | LB+ | LS+ | LR+ | LY+ | LI+ | LT+ | LU+ | MO+ | MK+ | MG+ | MW+ | MY+ | MV+ | ML+ | MT+ | MH+ | MQ+ | MR+ | MU+ | YT+ | MX+ | FM+ | MD+ | MC+ | MN+ | ME+ | MS+ | MA+ | MZ+ | MM+ | NA+ | NR+ | NP+ | NL+ | AN+ | NC+ | NZ+ | NI+ | NE+ | NG+ | NU+ | NF+ | MP+ | NO+ | OM+ | PK+ | PW+ | PS+ | PA+ | PG+ | PY+ | PE+ | PH+ | PN+ | PL+ | PT+ | PR+ | QA+ | RE+ | RO+ | RU+ | RW+ | BL+ | SH+ | KN+ | LC+ | MF+ | PM+ | VC+ | WS+ | SM+ | ST+ | SA+ | SN+ | RS+ | SC+ | SL+ | SG+ | SK+ | SI+ | SB+ | SO+ | ZA+ | GS+ | ES+ | LK+ | SD+ | SR+ | SJ+ | SZ+ | SE+ | CH+ | SY+ | TW+ | TJ+ | TZ+ | TH+ | TL+ | TG+ | TK+ | TO+ | TT+ | TN+ | TR+ | TM+ | TC+ | TV+ | UG+ | UA+ | AE+ | GB+ | US+ | UM+ | UY+ | UZ+ | VU+ | VE+ | VN+ | VG+ | VI+ | WF+ | EH+ | YE+ | ZM+ | ZW+ deriving (Data, Enum, Eq, Ord, Show, Typeable)++data ISOAlpha3Code = AFG+ | ALA+ | ALB+ | DZA+ | ASM+ | AND+ | AGO+ | AIA+ | ATA+ | ATG+ | ARG+ | ARM+ | ABW+ | AUS+ | AUT+ | AZE+ | BHS+ | BHR+ | BGD+ | BRB+ | BLR+ | BEL+ | BLZ+ | BEN+ | BMU+ | BTN+ | BOL+ | BIH+ | BWA+ | BVT+ | BRA+ | IOT+ | BRN+ | BGR+ | BFA+ | BDI+ | KHM+ | CMR+ | CAN+ | CPV+ | CYM+ | CAF+ | TCD+ | CHL+ | CHN+ | CXR+ | CCK+ | COL+ | COM+ | COG+ | COD+ | COK+ | CRI+ | CIV+ | HRV+ | CUB+ | CYP+ | CZE+ | DNK+ | DJI+ | DMA+ | DOM+ | ECU+ | EGY+ | SLV+ | GNQ+ | ERI+ | EST+ | ETH+ | FLK+ | FRO+ | FJI+ | FIN+ | FRA+ | GUF+ | PYF+ | ATF+ | GAB+ | GMB+ | GEO+ | DEU+ | GHA+ | GIB+ | GRC+ | GRL+ | GRD+ | GLP+ | GUM+ | GTM+ | GGY+ | GIN+ | GNB+ | GUY+ | HTI+ | HMD+ | VAT+ | HND+ | HKG+ | HUN+ | ISL+ | IND+ | IDN+ | IRN+ | IRQ+ | IRL+ | IMN+ | ISR+ | ITA+ | JAM+ | JPN+ | JEY+ | JOR+ | KAZ+ | KEN+ | KIR+ | PRK+ | KOR+ | KWT+ | KGZ+ | LAO+ | LVA+ | LBN+ | LSO+ | LBR+ | LBY+ | LIE+ | LTU+ | LUX+ | MAC+ | MKD+ | MDG+ | MWI+ | MYS+ | MDV+ | MLI+ | MLT+ | MHL+ | MTQ+ | MRT+ | MUS+ | MYT+ | MEX+ | FSM+ | MDA+ | MCO+ | MNG+ | MNE+ | MSR+ | MAR+ | MOZ+ | MMR+ | NAM+ | NRU+ | NPL+ | NLD+ | ANT+ | NCL+ | NZL+ | NIC+ | NER+ | NGA+ | NIU+ | NFK+ | MNP+ | NOR+ | OMN+ | PAK+ | PLW+ | PSE+ | PAN+ | PNG+ | PRY+ | PER+ | PHL+ | PCN+ | POL+ | PRT+ | PRI+ | QAT+ | REU+ | ROU+ | RUS+ | RWA+ | BLM+ | SHN+ | KNA+ | LCA+ | MAF+ | SPM+ | VCT+ | WSM+ | SMR+ | STP+ | SAU+ | SEN+ | SRB+ | SYC+ | SLE+ | SGP+ | SVK+ | SVN+ | SLB+ | SOM+ | ZAF+ | SGS+ | ESP+ | LKA+ | SDN+ | SUR+ | SJM+ | SWZ+ | SWE+ | CHE+ | SYR+ | TWN+ | TJK+ | TZA+ | THA+ | TLS+ | TGO+ | TKL+ | TON+ | TTO+ | TUN+ | TUR+ | TKM+ | TCA+ | TUV+ | UGA+ | UKR+ | ARE+ | GBR+ | USA+ | UMI+ | URY+ | UZB+ | VUT+ | VEN+ | VNM+ | VGB+ | VIR+ | WLF+ | ESH+ | YEM+ | ZMB+ | ZWE+ deriving (Data, Eq, Ord, Show, Typeable)++++data ISONumericCode = ISONumericCode [DecimalDigit]+ deriving (Data, Eq, Ord, Typeable)++instance Show ISONumericCode where+ show (ISONumericCode digits) = concatMap (show . decimal_digit_to_integral) digits++-- | A smart constructor to turn 'Integer's into 'ISONumericCode's. Note that the space of ISO-3166-1+-- numeric codes has many reserved or otherwise unused codes. This constructor does not verify that+-- its input is a valid ISO-3166-1 country code, it merely constructs a +isoNumericCode :: Integer -> ISONumericCode+isoNumericCode n | n < 10 = ISONumericCode $ Zero:Zero:(integral_to_digits n)+ | n < 100 = ISONumericCode $ Zero :(integral_to_digits n)+ | otherwise = ISONumericCode $ (integral_to_digits n)+++data ISOCountryCode = ISOCountryCode { isoAlpha2 :: ISOAlpha2Code+ , isoAlpha3 :: ISOAlpha3Code+ , isoNumeric :: ISONumericCode+ } deriving (Data, Eq, Ord, Show, Typeable)++++-- | 'countries_and_iso_country_codes' represents the bijection between 'Country's and +-- their 'ISOCountryCode's.+countries_and_iso_country_codes :: [ (Country, ISOCountryCode) ]+countries_and_iso_country_codes =++ [ ( Afghanistan , ISOCountryCode AF AFG (isoNumericCode 004) )+ , ( AlandIslands , ISOCountryCode AX ALA (isoNumericCode 248) )+ , ( Albania , ISOCountryCode AL ALB (isoNumericCode 008) )+ , ( Algeria , ISOCountryCode DZ DZA (isoNumericCode 012) )+ , ( AmericanSamoa , ISOCountryCode AS ASM (isoNumericCode 016) )+ , ( Andorra , ISOCountryCode AD AND (isoNumericCode 020) )+ , ( Angola , ISOCountryCode AO AGO (isoNumericCode 024) )+ , ( Anguilla , ISOCountryCode AI AIA (isoNumericCode 660) )+ , ( Antarctica , ISOCountryCode AQ ATA (isoNumericCode 010) )+ , ( AntiguaAndBarbuda , ISOCountryCode AG ATG (isoNumericCode 028) )+ , ( Argentina , ISOCountryCode AR ARG (isoNumericCode 032) )+ , ( Armenia , ISOCountryCode AM ARM (isoNumericCode 051) )+ , ( Aruba , ISOCountryCode AW ABW (isoNumericCode 533) )+ , ( Australia , ISOCountryCode AU AUS (isoNumericCode 036) )+ , ( Austria , ISOCountryCode AT AUT (isoNumericCode 040) )+ , ( Azerbaijan , ISOCountryCode AZ AZE (isoNumericCode 031) )+ , ( Bahamas , ISOCountryCode BS BHS (isoNumericCode 044) )+ , ( Bahrain , ISOCountryCode BH BHR (isoNumericCode 048) )+ , ( Bangladesh , ISOCountryCode BD BGD (isoNumericCode 050) )+ , ( Barbados , ISOCountryCode BB BRB (isoNumericCode 052) )+ , ( Belarus , ISOCountryCode BY BLR (isoNumericCode 112) )+ , ( Belgium , ISOCountryCode BE BEL (isoNumericCode 056) )+ , ( Belize , ISOCountryCode BZ BLZ (isoNumericCode 084) )+ , ( Benin , ISOCountryCode BJ BEN (isoNumericCode 204) )+ , ( Bermuda , ISOCountryCode BM BMU (isoNumericCode 060) )+ , ( Bhutan , ISOCountryCode BT BTN (isoNumericCode 064) )+ , ( Bolivia , ISOCountryCode BO BOL (isoNumericCode 068) )+ , ( BosniaAndHerzegovina , ISOCountryCode BA BIH (isoNumericCode 070) )+ , ( Botswana , ISOCountryCode BW BWA (isoNumericCode 072) )+ , ( BouvetIsland , ISOCountryCode BV BVT (isoNumericCode 074) )+ , ( Brazil , ISOCountryCode BR BRA (isoNumericCode 076) )+ , ( BritishIndianOceanTerritory , ISOCountryCode IO IOT (isoNumericCode 086) )+ , ( BruneiDarussalam , ISOCountryCode BN BRN (isoNumericCode 096) )+ , ( Bulgaria , ISOCountryCode BG BGR (isoNumericCode 100) )+ , ( BurkinaFaso , ISOCountryCode BF BFA (isoNumericCode 854) )+ , ( Burundi , ISOCountryCode BI BDI (isoNumericCode 108) )+ , ( Cambodia , ISOCountryCode KH KHM (isoNumericCode 116) )+ , ( Cameroon , ISOCountryCode CM CMR (isoNumericCode 120) )+ , ( Canada , ISOCountryCode CA CAN (isoNumericCode 124) )+ , ( CapeVerde , ISOCountryCode CV CPV (isoNumericCode 132) )+ , ( CaymanIslands , ISOCountryCode KY CYM (isoNumericCode 136) )+ , ( CentralAfricanRepublic , ISOCountryCode CF CAF (isoNumericCode 140) )+ , ( Chad , ISOCountryCode TD TCD (isoNumericCode 148) )+ , ( Chile , ISOCountryCode CL CHL (isoNumericCode 152) )+ , ( China , ISOCountryCode CN CHN (isoNumericCode 156) )+ , ( ChristmasIsland , ISOCountryCode CX CXR (isoNumericCode 162) )+ , ( CocosKeelingIslands , ISOCountryCode CC CCK (isoNumericCode 166) )+ , ( Colombia , ISOCountryCode CO COL (isoNumericCode 170) )+ , ( Comoros , ISOCountryCode KM COM (isoNumericCode 174) )+ , ( Congo , ISOCountryCode CG COG (isoNumericCode 178) )+ , ( DemocraticRepublicOfCongo , ISOCountryCode CD COD (isoNumericCode 180) )+ , ( CookIslands , ISOCountryCode CK COK (isoNumericCode 184) )+ , ( CostaRica , ISOCountryCode CR CRI (isoNumericCode 188) )+ , ( CoteDIvoire , ISOCountryCode CI CIV (isoNumericCode 384) )+ , ( Croatia , ISOCountryCode HR HRV (isoNumericCode 191) )+ , ( Cuba , ISOCountryCode CU CUB (isoNumericCode 192) )+ , ( Cyprus , ISOCountryCode CY CYP (isoNumericCode 196) )+ , ( CzechRepublic , ISOCountryCode CZ CZE (isoNumericCode 203) )+ , ( Denmark , ISOCountryCode DK DNK (isoNumericCode 208) )+ , ( Djibouti , ISOCountryCode DJ DJI (isoNumericCode 262) )+ , ( Dominica , ISOCountryCode DM DMA (isoNumericCode 212) )+ , ( DominicanRepublic , ISOCountryCode DO DOM (isoNumericCode 214) )+ , ( Ecuador , ISOCountryCode EC ECU (isoNumericCode 218) )+ , ( Egypt , ISOCountryCode EG EGY (isoNumericCode 818) )+ , ( ElSalvador , ISOCountryCode SV SLV (isoNumericCode 222) )+ , ( EquatorialGuinea , ISOCountryCode GQ GNQ (isoNumericCode 226) )+ , ( Eritrea , ISOCountryCode ER ERI (isoNumericCode 232) )+ , ( Estonia , ISOCountryCode EE EST (isoNumericCode 233) )+ , ( Ethiopia , ISOCountryCode ET ETH (isoNumericCode 231) )+ , ( FalklandIslands , ISOCountryCode FK FLK (isoNumericCode 238) )+ , ( FaroeIslands , ISOCountryCode FO FRO (isoNumericCode 234) )+ , ( Fiji , ISOCountryCode FJ FJI (isoNumericCode 242) )+ , ( Finland , ISOCountryCode FI FIN (isoNumericCode 246) )+ , ( France , ISOCountryCode FR FRA (isoNumericCode 250) )+ , ( FrenchGuiana , ISOCountryCode GF GUF (isoNumericCode 254) )+ , ( FrenchPolynesia , ISOCountryCode PF PYF (isoNumericCode 258) )+ , ( FrenchSouthernTerritories , ISOCountryCode TF ATF (isoNumericCode 260) )+ , ( Gabon , ISOCountryCode GA GAB (isoNumericCode 266) )+ , ( Gambia , ISOCountryCode GM GMB (isoNumericCode 270) )+ , ( Georgia , ISOCountryCode GE GEO (isoNumericCode 268) )+ , ( Germany , ISOCountryCode DE DEU (isoNumericCode 276) )+ , ( Ghana , ISOCountryCode GH GHA (isoNumericCode 288) )+ , ( Gibraltar , ISOCountryCode GI GIB (isoNumericCode 292) )+ , ( Greece , ISOCountryCode GR GRC (isoNumericCode 300) )+ , ( Greenland , ISOCountryCode GL GRL (isoNumericCode 304) )+ , ( Grenada , ISOCountryCode GD GRD (isoNumericCode 308) )+ , ( Guadeloupe , ISOCountryCode GP GLP (isoNumericCode 312) )+ , ( Guam , ISOCountryCode GU GUM (isoNumericCode 316) )+ , ( Guatemala , ISOCountryCode GT GTM (isoNumericCode 320) )+ , ( Guernsey , ISOCountryCode GG GGY (isoNumericCode 831) )+ , ( Guinea , ISOCountryCode GN GIN (isoNumericCode 324) )+ , ( GuineaBissau , ISOCountryCode GW GNB (isoNumericCode 624) )+ , ( Guyana , ISOCountryCode GY GUY (isoNumericCode 328) )+ , ( Haiti , ISOCountryCode HT HTI (isoNumericCode 332) )+ , ( HeardIslandAndMcDonaldIslands , ISOCountryCode HM HMD (isoNumericCode 334) )+ , ( HolySee , ISOCountryCode VA VAT (isoNumericCode 336) )+ , ( Honduras , ISOCountryCode HN HND (isoNumericCode 340) )+ , ( HongKong , ISOCountryCode HK HKG (isoNumericCode 344) )+ , ( Hungary , ISOCountryCode HU HUN (isoNumericCode 348) )+ , ( Iceland , ISOCountryCode IS ISL (isoNumericCode 352) )+ , ( India , ISOCountryCode IN IND (isoNumericCode 356) )+ , ( Indonesia , ISOCountryCode ID IDN (isoNumericCode 360) )+ , ( Iran , ISOCountryCode IR IRN (isoNumericCode 364) )+ , ( Iraq , ISOCountryCode IQ IRQ (isoNumericCode 368) )+ , ( Ireland , ISOCountryCode IE IRL (isoNumericCode 372) )+ , ( IsleOfMan , ISOCountryCode IM IMN (isoNumericCode 833) )+ , ( Israel , ISOCountryCode IL ISR (isoNumericCode 376) )+ , ( Italy , ISOCountryCode IT ITA (isoNumericCode 380) )+ , ( Jamaica , ISOCountryCode JM JAM (isoNumericCode 388) )+ , ( Japan , ISOCountryCode JP JPN (isoNumericCode 392) )+ , ( Jersey , ISOCountryCode JE JEY (isoNumericCode 832) )+ , ( Jordan , ISOCountryCode JO JOR (isoNumericCode 400) )+ , ( Kazakhstan , ISOCountryCode KZ KAZ (isoNumericCode 398) )+ , ( Kenya , ISOCountryCode KE KEN (isoNumericCode 404) )+ , ( Kiribati , ISOCountryCode KI KIR (isoNumericCode 296) )+ , ( NorthKorea , ISOCountryCode KP PRK (isoNumericCode 408) )+ , ( SouthKorea , ISOCountryCode KR KOR (isoNumericCode 410) )+ , ( Kuwait , ISOCountryCode KW KWT (isoNumericCode 414) )+ , ( Kyrgyzstan , ISOCountryCode KG KGZ (isoNumericCode 417) )+ , ( Laos , ISOCountryCode LA LAO (isoNumericCode 418) )+ , ( Latvia , ISOCountryCode LV LVA (isoNumericCode 428) )+ , ( Lebanon , ISOCountryCode LB LBN (isoNumericCode 422) )+ , ( Lesotho , ISOCountryCode LS LSO (isoNumericCode 426) )+ , ( Liberia , ISOCountryCode LR LBR (isoNumericCode 430) )+ , ( Libya , ISOCountryCode LY LBY (isoNumericCode 434) )+ , ( Liechtenstein , ISOCountryCode LI LIE (isoNumericCode 438) )+ , ( Lithuania , ISOCountryCode LT LTU (isoNumericCode 440) )+ , ( Luxembourg , ISOCountryCode LU LUX (isoNumericCode 442) )+ , ( Macao , ISOCountryCode MO MAC (isoNumericCode 446) )+ , ( Macedonia , ISOCountryCode MK MKD (isoNumericCode 807) )+ , ( Madagascar , ISOCountryCode MG MDG (isoNumericCode 450) )+ , ( Malawi , ISOCountryCode MW MWI (isoNumericCode 454) )+ , ( Malaysia , ISOCountryCode MY MYS (isoNumericCode 458) )+ , ( Maldives , ISOCountryCode MV MDV (isoNumericCode 462) )+ , ( Mali , ISOCountryCode ML MLI (isoNumericCode 466) )+ , ( Malta , ISOCountryCode MT MLT (isoNumericCode 470) )+ , ( MarshallIslands , ISOCountryCode MH MHL (isoNumericCode 584) )+ , ( Martinique , ISOCountryCode MQ MTQ (isoNumericCode 474) )+ , ( Mauritania , ISOCountryCode MR MRT (isoNumericCode 478) )+ , ( Mauritius , ISOCountryCode MU MUS (isoNumericCode 480) )+ , ( Mayotte , ISOCountryCode YT MYT (isoNumericCode 175) )+ , ( Mexico , ISOCountryCode MX MEX (isoNumericCode 484) )+ , ( Micronesia , ISOCountryCode FM FSM (isoNumericCode 583) )+ , ( Moldova , ISOCountryCode MD MDA (isoNumericCode 498) )+ , ( Monaco , ISOCountryCode MC MCO (isoNumericCode 492) )+ , ( Mongolia , ISOCountryCode MN MNG (isoNumericCode 496) )+ , ( Montenegro , ISOCountryCode ME MNE (isoNumericCode 499) )+ , ( Montserrat , ISOCountryCode MS MSR (isoNumericCode 500) )+ , ( Morocco , ISOCountryCode MA MAR (isoNumericCode 504) )+ , ( Mozambique , ISOCountryCode MZ MOZ (isoNumericCode 508) )+ , ( Myanmar , ISOCountryCode MM MMR (isoNumericCode 104) )+ , ( Namibia , ISOCountryCode NA NAM (isoNumericCode 516) )+ , ( Nauru , ISOCountryCode NR NRU (isoNumericCode 520) )+ , ( Nepal , ISOCountryCode NP NPL (isoNumericCode 524) )+ , ( Netherlands , ISOCountryCode NL NLD (isoNumericCode 528) )+ , ( NetherlandsAntilles , ISOCountryCode AN ANT (isoNumericCode 530) )+ , ( NewCaledonia , ISOCountryCode NC NCL (isoNumericCode 540) )+ , ( NewZealand , ISOCountryCode NZ NZL (isoNumericCode 554) )+ , ( Nicaragua , ISOCountryCode NI NIC (isoNumericCode 558) )+ , ( Niger , ISOCountryCode NE NER (isoNumericCode 562) )+ , ( Nigeria , ISOCountryCode NG NGA (isoNumericCode 566) )+ , ( Niue , ISOCountryCode NU NIU (isoNumericCode 570) )+ , ( NorfolkIsland , ISOCountryCode NF NFK (isoNumericCode 574) )+ , ( NorthernMarianaIslands , ISOCountryCode MP MNP (isoNumericCode 580) )+ , ( Norway , ISOCountryCode NO NOR (isoNumericCode 578) )+ , ( Oman , ISOCountryCode OM OMN (isoNumericCode 512) )+ , ( Pakistan , ISOCountryCode PK PAK (isoNumericCode 586) )+ , ( Palau , ISOCountryCode PW PLW (isoNumericCode 585) )+ , ( Palestinine , ISOCountryCode PS PSE (isoNumericCode 275) )+ , ( Panama , ISOCountryCode PA PAN (isoNumericCode 591) )+ , ( PapuaNewGuinea , ISOCountryCode PG PNG (isoNumericCode 598) )+ , ( Paraguay , ISOCountryCode PY PRY (isoNumericCode 600) )+ , ( Peru , ISOCountryCode PE PER (isoNumericCode 604) )+ , ( Philippines , ISOCountryCode PH PHL (isoNumericCode 608) )+ , ( Pitcairn , ISOCountryCode PN PCN (isoNumericCode 612) )+ , ( Poland , ISOCountryCode PL POL (isoNumericCode 616) )+ , ( Portugal , ISOCountryCode PT PRT (isoNumericCode 620) )+ , ( PuertoRico , ISOCountryCode PR PRI (isoNumericCode 630) )+ , ( Qatar , ISOCountryCode QA QAT (isoNumericCode 634) )+ , ( Reunion , ISOCountryCode RE REU (isoNumericCode 638) )+ , ( Romania , ISOCountryCode RO ROU (isoNumericCode 642) )+ , ( RussianFederation , ISOCountryCode RU RUS (isoNumericCode 643) )+ , ( Rwanda , ISOCountryCode RW RWA (isoNumericCode 646) )+ , ( SaintBarthelemy , ISOCountryCode BL BLM (isoNumericCode 652) )+ , ( SaintHelenaAscensionAndTristanDaCunha , ISOCountryCode SH SHN (isoNumericCode 654) )+ , ( SaintKittsAndNevis , ISOCountryCode KN KNA (isoNumericCode 659) )+ , ( SaintLucia , ISOCountryCode LC LCA (isoNumericCode 662) )+ , ( SaintMartin , ISOCountryCode MF MAF (isoNumericCode 663) )+ , ( SaintPierreAndMiquelon , ISOCountryCode PM SPM (isoNumericCode 666) )+ , ( SaintVincentAndTheGrenadines , ISOCountryCode VC VCT (isoNumericCode 670) )+ , ( Samoa , ISOCountryCode WS WSM (isoNumericCode 882) )+ , ( SanMarino , ISOCountryCode SM SMR (isoNumericCode 674) )+ , ( SaoTomeAndPrincipe , ISOCountryCode ST STP (isoNumericCode 678) )+ , ( SaudiArabia , ISOCountryCode SA SAU (isoNumericCode 682) )+ , ( Senegal , ISOCountryCode SN SEN (isoNumericCode 686) )+ , ( Serbia , ISOCountryCode RS SRB (isoNumericCode 688) )+ , ( Seychelles , ISOCountryCode SC SYC (isoNumericCode 690) )+ , ( SierraLeone , ISOCountryCode SL SLE (isoNumericCode 694) )+ , ( Singapore , ISOCountryCode SG SGP (isoNumericCode 702) )+ , ( Slovakia , ISOCountryCode SK SVK (isoNumericCode 703) )+ , ( Slovenia , ISOCountryCode SI SVN (isoNumericCode 705) )+ , ( SolomonIslands , ISOCountryCode SB SLB (isoNumericCode 090) )+ , ( Somalia , ISOCountryCode SO SOM (isoNumericCode 706) )+ , ( SouthAfrica , ISOCountryCode ZA ZAF (isoNumericCode 710) )+ , ( SouthGeorgiaAndtheSouthSandwichIslands , ISOCountryCode GS SGS (isoNumericCode 239) )+ , ( Spain , ISOCountryCode ES ESP (isoNumericCode 724) )+ , ( SriLanka , ISOCountryCode LK LKA (isoNumericCode 144) )+ , ( Sudan , ISOCountryCode SD SDN (isoNumericCode 736) )+ , ( Suriname , ISOCountryCode SR SUR (isoNumericCode 740) )+ , ( SvalbardAndJanMayen , ISOCountryCode SJ SJM (isoNumericCode 744) )+ , ( Swaziland , ISOCountryCode SZ SWZ (isoNumericCode 748) )+ , ( Sweden , ISOCountryCode SE SWE (isoNumericCode 752) )+ , ( Switzerland , ISOCountryCode CH CHE (isoNumericCode 756) )+ , ( Syria , ISOCountryCode SY SYR (isoNumericCode 760) )+ , ( Taiwan , ISOCountryCode TW TWN (isoNumericCode 158) )+ , ( Tajikistan , ISOCountryCode TJ TJK (isoNumericCode 762) )+ , ( Tanzania , ISOCountryCode TZ TZA (isoNumericCode 834) )+ , ( Thailand , ISOCountryCode TH THA (isoNumericCode 764) )+ , ( TimorLeste , ISOCountryCode TL TLS (isoNumericCode 626) )+ , ( Togo , ISOCountryCode TG TGO (isoNumericCode 768) )+ , ( Tokelau , ISOCountryCode TK TKL (isoNumericCode 772) )+ , ( Tonga , ISOCountryCode TO TON (isoNumericCode 776) )+ , ( TrinidadAndTobago , ISOCountryCode TT TTO (isoNumericCode 780) )+ , ( Tunisia , ISOCountryCode TN TUN (isoNumericCode 788) )+ , ( Turkey , ISOCountryCode TR TUR (isoNumericCode 792) )+ , ( Turkmenistan , ISOCountryCode TM TKM (isoNumericCode 795) )+ , ( TurksAndCaicosIslands , ISOCountryCode TC TCA (isoNumericCode 796) )+ , ( Tuvalu , ISOCountryCode TV TUV (isoNumericCode 798) )+ , ( Uganda , ISOCountryCode UG UGA (isoNumericCode 800) )+ , ( Ukraine , ISOCountryCode UA UKR (isoNumericCode 804) )+ , ( UnitedArabEmirates , ISOCountryCode AE ARE (isoNumericCode 784) )+ , ( UnitedKingdom , ISOCountryCode GB GBR (isoNumericCode 826) )+ , ( UnitedStates , ISOCountryCode US USA (isoNumericCode 840) )+ , ( UnitedStatesMinorOutlyingIslands , ISOCountryCode UM UMI (isoNumericCode 581) )+ , ( Uruguay , ISOCountryCode UY URY (isoNumericCode 858) )+ , ( Uzbekistan , ISOCountryCode UZ UZB (isoNumericCode 860) )+ , ( Vanuatu , ISOCountryCode VU VUT (isoNumericCode 548) )+ , ( Venezuela , ISOCountryCode VE VEN (isoNumericCode 862) )+ , ( VietNam , ISOCountryCode VN VNM (isoNumericCode 704) )+ , ( BritishVirginIslands , ISOCountryCode VG VGB (isoNumericCode 092) )+ , ( USVirginIslands , ISOCountryCode VI VIR (isoNumericCode 850) )+ , ( WallisAndFutuna , ISOCountryCode WF WLF (isoNumericCode 876) )+ , ( WesternSahara , ISOCountryCode EH ESH (isoNumericCode 732) )+ , ( Yemen , ISOCountryCode YE YEM (isoNumericCode 887) )+ , ( Zambia , ISOCountryCode ZM ZMB (isoNumericCode 894) )+ , ( Zimbabwe , ISOCountryCode ZW ZWE (isoNumericCode 716) )+ ]+++++-- | A \"table\" of 'ISOCountryCode's, each of which is a relation in three values.+-- By construction, these are the only valid ISOCountryCode values. ++valid_iso_country_codes :: [ISOCountryCode]+valid_iso_country_codes = fmap snd countries_and_iso_country_codes++-- | A \"table\" of 'ISONumericCode's, each of which is a relation in three values.+-- By construction, these are the only valid 'ISONumericCode' values. +++valid_iso_numeric_codes :: [ISONumericCode]+valid_iso_numeric_codes = fmap isoNumeric valid_iso_country_codes+++validate_isoNumericCode :: ISONumericCode -> Maybe ISONumericCode+validate_isoNumericCode code = if (code `elem` valid_iso_numeric_codes)+ then (Just code)+ else (Nothing)++++type UNShortName = String+type UNFormalName = String+++-- | The CountryName type encodes "all" the names for+data CountryName = CountryName { english_short_name :: UNShortName+ , english_formal_name :: UNFormalName+ } deriving (Data, Eq, Ord, Show, Typeable)+++-- | These names come either from the United Nations document "Terminology Bulletin Country Names"+-- or "Country and Region Codes for Statistical Use" as described by ISO-3166-1. This data is naturally+-- tabular, and it is worth keeping in that form despite the extreme width of the textual representation.++countries_and_united_nations_names :: [(Country, CountryName)]+countries_and_united_nations_names = -- English Short Name English Formal Name+ [ ( Afghanistan , CountryName "Afghanistan" "Islamic Republic of Afghanistan" )+ , ( AlandIslands , CountryName "Åland Islands" "Åland Islands" )+ , ( Albania , CountryName "Albania" "Republic of Albania" )+ , ( Algeria , CountryName "Algeria" "People's Democratic Republic of Algeria" )+ , ( AmericanSamoa , CountryName "American Samoa" "American Samoa" )+ , ( Andorra , CountryName "Andorra" "Principality of Andorra" )+ , ( Angola , CountryName "Angola" "Republic of Angola" )+ , ( Anguilla , CountryName "Anguilla" "Anguilla" )+ , ( Antarctica , CountryName "Antarctica" "Antarctica" )+ , ( AntiguaAndBarbuda , CountryName "Antigua and Barbuda" "Antigua and Barbuda" )+ , ( Argentina , CountryName "Argentina" "Argentine Republic" )+ , ( Armenia , CountryName "Armenia" "Republic of Armenia" )+ , ( Aruba , CountryName "Aruba" "Aruba" )+ , ( Australia , CountryName "Australia" "Australia" )+ , ( Austria , CountryName "Austria" "Republic of Austria" )+ , ( Azerbaijan , CountryName "Azerbaijan" "Republic of Azerbaijan" )+ , ( Bahamas , CountryName "Bahamas" "Commonwealth of the Bahamas" )+ , ( Bahrain , CountryName "Bahrain" "Kingdom of Bahrain" )+ , ( Bangladesh , CountryName "Bangladesh" "People's Republic of Bangladesh" )+ , ( Barbados , CountryName "Barbados" "Barbados" )+ , ( Belarus , CountryName "Belarus" "Republic of Belarus" )+ , ( Belgium , CountryName "Belgium" "Kingdom of Belgium" )+ , ( Belize , CountryName "Belize" "Belize" )+ , ( Benin , CountryName "Benin" "Republic of Benin" )+ , ( Bermuda , CountryName "Bermuda" "Bermuda" )+ , ( Bhutan , CountryName "Bhutan" "Kingdom of Bhutan" )+ , ( Bolivia , CountryName "Bolivia" "Plurinational State of Bolivia" )+ , ( BosniaAndHerzegovina , CountryName "Bosnia and Herzegovina" "Bosnia and Herzegovina" )+ , ( Botswana , CountryName "Botswana" "Republic of Botswana" )+ , ( BouvetIsland , CountryName "Bouvet Island" "Bouvet Island" )+ , ( Brazil , CountryName "Brazil" "Federative Republic of Brazil" )+ , ( BritishIndianOceanTerritory , CountryName "British Indian Ocean Territory" "British Indian Ocean Territory" )+ , ( BruneiDarussalam , CountryName "Brunei Darussalam" "Brunei Darussalam" )+ , ( Bulgaria , CountryName "Bulgaria" "Republic of Bulgaria" )+ , ( BurkinaFaso , CountryName "Burkina Faso" "Burkina Faso" )+ , ( Burundi , CountryName "Burundi" "Republic of Burundi" )+ , ( Cambodia , CountryName "Cambodia" "Kingdom of Cambodia" )+ , ( Cameroon , CountryName "Cameroon" "Republic of Cameroon" )+ , ( Canada , CountryName "Canada" "Canada" )+ , ( CapeVerde , CountryName "Cape Verde" "Republic of Cape Verde" )+ , ( CaymanIslands , CountryName "Cayman Islands" "Cayman Islands" )+ , ( CentralAfricanRepublic , CountryName "Central African Republic" "Central African Republic" )+ , ( Chad , CountryName "Chad" "Republic of Chad" )+ , ( Chile , CountryName "Chile" "Republic of Chile" )+ , ( China , CountryName "China" "People's Republic of China" )+ , ( ChristmasIsland , CountryName "Christmas Island" "Christmas Island" )+ , ( CocosKeelingIslands , CountryName "Cocos (Keeling) Islands" "Cocos (Keeling) Islands" )+ , ( Colombia , CountryName "Colombia" "Republic of Colombia" )+ , ( Comoros , CountryName "Comoros" "Union of he Comoros" )+ , ( Congo , CountryName "Congo" "Republic of the Congo" )+ , ( DemocraticRepublicOfCongo , CountryName "Democratic Republic Of Congo" "Democratic Republic of the Congo" )+ , ( CookIslands , CountryName "Cook Islands" "Cook Islands" )+ , ( CostaRica , CountryName "Costa Rica" "Republic of Costa Rica" )+ , ( CoteDIvoire , CountryName "Côte d'Ivoire" "Republic of Côte d'Ivoire" )+ , ( Croatia , CountryName "Croatia" "Republic of Croatia" )+ , ( Cuba , CountryName "Cuba" "Republic of Cuba" )+ , ( Cyprus , CountryName "Cyprus" "Republic of Cyprus" )+ , ( CzechRepublic , CountryName "Czech Republic" "Czech Republic" )+ , ( Denmark , CountryName "Denmark" "Kingdom of Denmark" )+ , ( Djibouti , CountryName "Djibouti" "Republic of Djibouti" )+ , ( Dominica , CountryName "Dominica" "Commonwealth of Dominica" )+ , ( DominicanRepublic , CountryName "Dominican Republic" "Dominican Republic" )+ , ( Ecuador , CountryName "Ecuador" "Republic of Ecuador" )+ , ( Egypt , CountryName "Egypt" "Arab Republic of Egypt" )+ , ( ElSalvador , CountryName "El Salvador" "Republic of El Salvador" )+ , ( EquatorialGuinea , CountryName "Equatorial Guinea" "Republic of Equatorial Guinea" )+ , ( Eritrea , CountryName "Eritrea" "Eritrea" )+ , ( Estonia , CountryName "Estonia" "Republic of Estonia" )+ , ( Ethiopia , CountryName "Ethiopia" "Federal Democratic Republic of Ethiopia" )+ , ( FalklandIslands , CountryName "Falkland Islands" "Falkland Islands (Malvinas)" )+ , ( FaroeIslands , CountryName "Faroe Islands" "Faroe Islands" )+ , ( Fiji , CountryName "Fiji" "Republic of Fiji Islands" )+ , ( Finland , CountryName "Finland" "Republic of Finland" )+ , ( France , CountryName "France" "French Republic" )+ , ( FrenchGuiana , CountryName "French Guiana" "French Guiana" )+ , ( FrenchPolynesia , CountryName "French Polynesia" "French Polynesia" )+ , ( FrenchSouthernTerritories , CountryName "French Southern Territories" "French Southern Territories" )+ , ( Gabon , CountryName "Gabon" "Gabonese Republic" )+ , ( Gambia , CountryName "Gambia" "Republic of the Gambia" )+ , ( Georgia , CountryName "Georgia" "Georgia" )+ , ( Germany , CountryName "Germany" "Federal Republic of Germany" )+ , ( Ghana , CountryName "Ghana" "Republic of Ghana" )+ , ( Gibraltar , CountryName "Gibraltar" "Gibraltar" )+ , ( Greece , CountryName "Greece" "Hellenic Republic" )+ , ( Greenland , CountryName "Greenland" "Greenland" )+ , ( Grenada , CountryName "Grenada" "Grenada" )+ , ( Guadeloupe , CountryName "Guadeloupe" "Guadeloupe" )+ , ( Guam , CountryName "Guam" "Guam" )+ , ( Guatemala , CountryName "Guatemala" "Republic of Guatemala" )+ , ( Guernsey , CountryName "Guernsey" "Guernsey" )+ , ( Guinea , CountryName "Guinea" "Republic of Guinea" )+ , ( GuineaBissau , CountryName "Guinea Bissau" "Republic of Guinea-Bissau" )+ , ( Guyana , CountryName "Guyana" "Republic of Guyana" )+ , ( Haiti , CountryName "Haiti" "Republic of Haiti" )+ , ( HeardIslandAndMcDonaldIslands , CountryName "Heard Island And McDonald Islands" "Heard Island And McDonald Islands" )+ , ( HolySee , CountryName "Vatican City" "Holy See" )+ , ( Honduras , CountryName "Honduras" "Republic of Honduras" )+ , ( HongKong , CountryName "Hong Kong" "Hong Kong" )+ , ( Hungary , CountryName "Hungary" "Republic of Hungary" )+ , ( Iceland , CountryName "Iceland" "Republic of Iceland" )+ , ( India , CountryName "India" "Republic of India" )+ , ( Indonesia , CountryName "Indonesia" "Republic of Indonesia" )+ , ( Iran , CountryName "Iran" "Islamic Republic of Iran" )+ , ( Iraq , CountryName "Iraq" "Republic of Iraq" )+ , ( Ireland , CountryName "Ireland" "Ireland" )+ , ( IsleOfMan , CountryName "Isle Of Man" "Isle Of Man" )+ , ( Israel , CountryName "Israel" "State of Israel" )+ , ( Italy , CountryName "Italy" "Republic of Italy" )+ , ( Jamaica , CountryName "Jamaica" "Jamaica" )+ , ( Japan , CountryName "Japan" "Japan" )+ , ( Jersey , CountryName "Jersey" "Jersey" )+ , ( Jordan , CountryName "Jordan" "Hashemite Kingdom of Jordan" )+ , ( Kazakhstan , CountryName "Kazakhstan" "Republic of Kazakhstan" )+ , ( Kenya , CountryName "Kenya" "Republic of Kenya" )+ , ( Kiribati , CountryName "Kiribati" "Republic of Kiribati" )+ , ( NorthKorea , CountryName "North Korea" "Democratic People's Republic of Korea" )+ , ( SouthKorea , CountryName "South Korea" "Republic of Korea" )+ , ( Kuwait , CountryName "Kuwait" "State of Kuwait" )+ , ( Kyrgyzstan , CountryName "Kyrgyzstan" "Kyrgyz Republic" )+ , ( Laos , CountryName "Laos" "Lao People's Democratic Republic" )+ , ( Latvia , CountryName "Latvia" "Republic of Latvia" )+ , ( Lebanon , CountryName "Lebanon" "Lebanese Republic" )+ , ( Lesotho , CountryName "Lesotho" "Kingdom of Lesotho" )+ , ( Liberia , CountryName "Liberia" "Republic of Liberia" )+ , ( Libya , CountryName "Libya" "Socialist People's Libyan Arab Jamahiriya" )+ , ( Liechtenstein , CountryName "Liechtenstein" "Principality of Liechtenstein" )+ , ( Lithuania , CountryName "Lithuania" "Republic of Lithuania" )+ , ( Luxembourg , CountryName "Luxembourg" "Grand Duchy of Luxembourg" )+ , ( Macao , CountryName "Macao" "Macao" )+ , ( Macedonia , CountryName "Macedonia" "The former Yugoslav Republic of Macedonia" )+ , ( Madagascar , CountryName "Madagascar" "Republic of Madagascar" )+ , ( Malawi , CountryName "Malawi" "Republic of Malawi" )+ , ( Malaysia , CountryName "Malaysia" "Malaysia" )+ , ( Maldives , CountryName "Maldives" "Republic of Maldives" )+ , ( Mali , CountryName "Mali" "Republic of Mali" )+ , ( Malta , CountryName "Malta" "Republic of Malta" )+ , ( MarshallIslands , CountryName "Marshall Islands" "Republic of the Marshall Islands" )+ , ( Martinique , CountryName "Martinique" "Martinique" )+ , ( Mauritania , CountryName "Mauritania" "Mauritania" )+ , ( Mauritius , CountryName "Mauritius" "Republic of Mauritius" )+ , ( Mayotte , CountryName "Mayotte" "Mayotte" )+ , ( Mexico , CountryName "Mexico" "United Mexican States" )+ , ( Micronesia , CountryName "Micronesia" "Federated States of Micronesia" )+ , ( Moldova , CountryName "Moldova" "Republic of Moldova" )+ , ( Monaco , CountryName "Monaco" "Principality of Monaco" )+ , ( Mongolia , CountryName "Mongolia" "Mongolia" )+ , ( Montenegro , CountryName "Montenegro" "Montenegro" )+ , ( Montserrat , CountryName "Montserrat" "Montserrat" )+ , ( Morocco , CountryName "Morocco" "Kingdom of Morocco" )+ , ( Mozambique , CountryName "Mozambique" "Republic of Mozambique" )+ , ( Myanmar , CountryName "Myanmar" "Union of Myanmar" )+ , ( Namibia , CountryName "Namibia" "Republic of Namibia" )+ , ( Nauru , CountryName "Nauru" "Republic of Nauru" )+ , ( Nepal , CountryName "Nepal" "Federal Democratic Republic of Nepal" )+ , ( Netherlands , CountryName "Netherlands" "Kingdom of the Netherlands" )+ , ( NetherlandsAntilles , CountryName "Netherlands Antilles" "Netherlands Antilles" )+ , ( NewCaledonia , CountryName "New Caledonia" "New Caledonia" )+ , ( NewZealand , CountryName "New Zealand" "New Zealand" )+ , ( Nicaragua , CountryName "Nicaragua" "Republic of Nicaragua" )+ , ( Niger , CountryName "Niger" "Republic of Niger" )+ , ( Nigeria , CountryName "Nigeria" "Federal Republic of Nigeria" )+ , ( Niue , CountryName "Niue" "Niue" )+ , ( NorfolkIsland , CountryName "Norfolk Island" "Norfolk Island" )+ , ( NorthernMarianaIslands , CountryName "Northern Mariana Islands" "Northern Mariana Islands" )+ , ( Norway , CountryName "Norway" "Kingdom of Norway" )+ , ( Oman , CountryName "Oman" "Sultanate of Oman" )+ , ( Pakistan , CountryName "Pakistan" "Islamic Republic of Pakistan" )+ , ( Palau , CountryName "Palau" "Republic of Palau" )+ , ( Palestinine , CountryName "Palestine" "Occupied Palestinian Territory" )+ , ( Panama , CountryName "Panama" "Republic of Panama" )+ , ( PapuaNewGuinea , CountryName "Papua New Guinea" "Papua New Guinea" )+ , ( Paraguay , CountryName "Paraguay" "Republic of Paraguay" )+ , ( Peru , CountryName "Peru" "Republic of Peru" )+ , ( Philippines , CountryName "Philippines" "Republic of the Philippines" )+ , ( Pitcairn , CountryName "Pitcairn" "Pitcairn" )+ , ( Poland , CountryName "Poland" "Republic of Poland" )+ , ( Portugal , CountryName "Portugal" "Portuguese Republic" )+ , ( PuertoRico , CountryName "Puerto Rico" "Puerto Rico" )+ , ( Qatar , CountryName "Qatar" "State of Qatar" )+ , ( Reunion , CountryName "Réunion" "Réunion" )+ , ( Romania , CountryName "Romania" "Romania" )+ , ( RussianFederation , CountryName "Russian Federation" "Russian Federation" )+ , ( Rwanda , CountryName "Rwanda" "Republic of Rwanda" )+ , ( SaintBarthelemy , CountryName "Saint Barthélemy" "Saint Barthélemy" )+ , ( SaintHelenaAscensionAndTristanDaCunha , CountryName "Saint Helena, Ascension, and Tristan da Cunha" "Saint Helena, Ascension, and Tristan da Cunha" )+ , ( SaintKittsAndNevis , CountryName "Saint Kitts And Nevis" "Saint Kitts And Nevis" )+ , ( SaintLucia , CountryName "Saint Lucia" "Saint Lucia" )+ , ( SaintMartin , CountryName "Saint Martin" "Saint Martin" )+ , ( SaintPierreAndMiquelon , CountryName "Saint Pierre and Miquelon" "Saint Pierre and Miquelon" )+ , ( SaintVincentAndTheGrenadines , CountryName "Saint Vincent and the Grenadines" "Saint Vincent and the Grenadines" )+ , ( Samoa , CountryName "Samoa" "Independen State of Samoa" )+ , ( SanMarino , CountryName "San Marino" "Republic of San Marino" )+ , ( SaoTomeAndPrincipe , CountryName "Sao Tome and Principe" "Democratic Republic of Sao Tome and Principe" )+ , ( SaudiArabia , CountryName "Saudi Arabia" "Kingdom of Saudi Arabia" )+ , ( Senegal , CountryName "Senegal" "Republic of Senegal" )+ , ( Serbia , CountryName "Serbia" "Republic of Serbia" )+ , ( Seychelles , CountryName "Seychelles" "Republic of Seychelles" )+ , ( SierraLeone , CountryName "Sierra Leone" "Republic of Sierra Leone" )+ , ( Singapore , CountryName "Singapore" "Republic of Singapore" )+ , ( Slovakia , CountryName "Slovakia" "Slovak Republic" )+ , ( Slovenia , CountryName "Slovenia" "Republic of Slovenia" )+ , ( SolomonIslands , CountryName "Solomon Islands" "Solomon Islands" )+ , ( Somalia , CountryName "Somalia" "Somali Republic" )+ , ( SouthAfrica , CountryName "South Africa" "Republic of South Africa" )+ , ( SouthGeorgiaAndtheSouthSandwichIslands , CountryName "South Georgia and the South Sandwich Islands" "South Georgia And the South Sandwich Islands" )+ , ( Spain , CountryName "Spain" "Kingdom of Spain" )+ , ( SriLanka , CountryName "Sri Lanka" "Democratic Socialist Republic of Sri Lanka" )+ , ( Sudan , CountryName "Sudan" "Republic of Sudan" )+ , ( Suriname , CountryName "Suriname" "Republic of Suriname" )+ , ( SvalbardAndJanMayen , CountryName "Svalbard And Jan Mayen" "Svalbard And Jan Mayen" )+ , ( Swaziland , CountryName "Swaziland" "Kingdom of Swaziland" )+ , ( Sweden , CountryName "Sweden" "Kingdom of Sweden" )+ , ( Switzerland , CountryName "Switzerland" "Swiss Confederation" )+ , ( Syria , CountryName "Syrian Arab Republic" "Syrian Arab Republic" )+ , ( Taiwan , CountryName "Taiwan" "Province of China, Taiwan" )+ , ( Tajikistan , CountryName "Tajikistan" "Republic of Tajikistan" )+ , ( Tanzania , CountryName "Tanzania" "United Republic of Tanzania" )+ , ( Thailand , CountryName "Thailand" "Kingdom of Thailand" )+ , ( TimorLeste , CountryName "Timor-Leste" "Democratic Republic of Timor-Leste" )+ , ( Togo , CountryName "Togo" "Togolese Republic" )+ , ( Tokelau , CountryName "Tokelau" "Tokelau" )+ , ( Tonga , CountryName "Tonga" "Tonga" )+ , ( TrinidadAndTobago , CountryName "Trinidad And Tobago" "Republic of Trinidad And Tobago" )+ , ( Tunisia , CountryName "Tunisia" "Republic of Tunisia" )+ , ( Turkey , CountryName "Turkey" "Republic of Turkey" )+ , ( Turkmenistan , CountryName "Turkmenistan" "Turkmenistan" )+ , ( TurksAndCaicosIslands , CountryName "Turks And Caicos Islands" "Turks And Caicos Islands" )+ , ( Tuvalu , CountryName "Tuvalu" "Tuvalu" )+ , ( Uganda , CountryName "Uganda" "Republic of Uganda" )+ , ( Ukraine , CountryName "Ukraine" "Ukraine" )+ , ( UnitedArabEmirates , CountryName "United Arab Emirates" "United Arab Emirates" )+ , ( UnitedKingdom , CountryName "United Kingdom" "United Kingdom of Great Britain and Norther Ireland" )+ , ( UnitedStates , CountryName "United States" "United States of America" )+ , ( UnitedStatesMinorOutlyingIslands , CountryName "United States Minor Outlying Islands" "United States Minor Outlying Islands" )+ , ( Uruguay , CountryName "Uruguay" "Eastern Republic of Uruguay" )+ , ( Uzbekistan , CountryName "Uzbekistan" "Republic of Uzbekistan" )+ , ( Vanuatu , CountryName "Vanuatu" "Republic of Vanuatu" )+ , ( Venezuela , CountryName "Bolivia" "Bolivarian Republic of Venezuela" )+ , ( VietNam , CountryName "Vietnam" "Socialist Republic of Viet Nam" )+ , ( BritishVirginIslands , CountryName "British Virgin Islands" "British Virgin Islands" )+ , ( USVirginIslands , CountryName "U.S. Virgin Islands" "U.S. Virgin Islands" )+ , ( WallisAndFutuna , CountryName "Wallis And Futuna" "Wallis And Futuna" )+ , ( WesternSahara , CountryName "Western Sahara" "Western Sahara" )+ , ( Yemen , CountryName "Yemen" "Republic of Yemen" )+ , ( Zambia , CountryName "Zambia" "Republic of Zambia" )+ , ( Zimbabwe , CountryName "Zimbabwe" "Republic of Zimbabwe" )+ ]
+ src/Facts/Geography/Countries/Internal/Splices.hs view
@@ -0,0 +1,39 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE TemplateHaskell #-}++module Facts.Geography.Countries.Internal.Splices where++import Data.Data+import Data.Numerals.Decimal+import Data.Typeable++import Facts.Geography.Countries.Internal.Data+import Facts.Utility.Templates++import Prelude hiding (GT, LT)++import Test.QuickCheck+import Test.QuickCheck.Gen+++$( list_to_bijection "_country_code_by_country" "_country_by_country_code" countries_and_iso_country_codes)++$( list_to_injection "_country_name_by_country" countries_and_united_nations_names )++$( list_to_injection_via_pushout "_isoAlpha2_for_country" isoAlpha2 countries_and_iso_country_codes )+$( list_to_injection_via_pushout "_isoAlpha3_for_country" isoAlpha3 countries_and_iso_country_codes )+$( list_to_injection_via_pushout "_isoNumeric_for_country" isoNumeric countries_and_iso_country_codes )++$( list_to_injection_via_pullback "_country_for_isoAlpha2" isoAlpha2 countries_and_iso_country_codes )+$( list_to_injection_via_pullback "_country_for_isoAlpha3" isoAlpha3 countries_and_iso_country_codes )+$( list_to_injection_via_pullback "_country_for_isoNumeric" isoNumeric countries_and_iso_country_codes )++++$( list_to_injection_via_pushout "_shortEnglishCountryName" english_short_name countries_and_united_nations_names )+$( list_to_injection_via_pushout "_formalEnglishCountryName" english_formal_name countries_and_united_nations_names )
+ src/Facts/Geography/Countries/UnitedStates.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE TypeSynonymInstances #-}++module Facts.Geography.Countries.UnitedStates ( State (..)+ , StateAbbreviation (..)+ , StateCode+ , OtherUSEntity (..)+ , state_by_state_code+ , state_code_by_state+ ) where+++import Facts.Geography.Countries.UnitedStates.Internal.Data+import Facts.Geography.Countries.UnitedStates.Internal.Splices++import Data.Char+import Data.Data+import Data.Functor+import Data.Maybe+import Data.Typeable++import Test.QuickCheck+import Test.QuickCheck.Gen++++++instance Show State where+ show Alabama = "Alabama"+ show Alaska = "Alaska"+ show Arkansas = "Arkansas"+ show Arizona = "Arizona"+ show California = "California"+ show Colorodo = "Colorodo"+ show Connecticut = "Connecticut"+ show Delaware = "Delaware"+ show Florida = "Florida"+ show Georgia = "Georgia"+ show Hawaii = "Hawaii"+ show Idaho = "Idaho"+ show Illinois = "Illinois"+ show Indiana = "Indiana"+ show Iowa = "Iowa"+ show Kansas = "Kansas"+ show Kentucky = "Kentucky"+ show Louisiana = "Louisiana"+ show Maine = "Maine"+ show Maryland = "Maryland"+ show Massachusetts = "Massachusetts"+ show Michigan = "Michigan"+ show Minnesota = "Minnesota"+ show Mississippi = "Mississippi"+ show Missouri = "Missouri"+ show Montana = "Montana"+ show Nebraska = "Nebraska"+ show Nevada = "Nevada"+ show NewHampshire = "New Hampshire"+ show NewJersey = "New Jersey"+ show NewMexico = "New Mexico"+ show NewYork = "New York"+ show NorthCarolina = "North Carolina"+ show NorthDakota = "North Dakota"+ show Ohio = "Ohio"+ show Oklahoma = "Oklahoma"+ show Oregon = "Oregon"+ show Pennsylvania = "Pennsylvania"+ show RhodeIsland = "Rhode Island"+ show SouthCarolina = "South Carolina"+ show SouthDakota = "South Dakota"+ show Tennessee = "Tennessee"+ show Texas = "Texas"+ show Utah = "Utah"+ show Vermont = "Vermont"+ show Virginia = "Virginia"+ show Washington = "Washington"+ show WestVirginia = "West Virginia"+ show Wisconsin = "Wisconsin"+ show Wyoming = "Wyoming"+++type StateCode = StateAbbreviation+++instance Arbitrary State where+ arbitrary = elements [Alabama .. Wyoming]++instance Arbitrary StateCode where+ arbitrary = elements [AL .. WY]+ ++ +prop_state_and_state_code_are_inverses :: State -> Bool+prop_state_and_state_code_are_inverses state = (state_by_state_code . state_code_by_state $ state) == state++prop_state_code_and_state_are_inverses :: StateCode -> Bool+prop_state_code_and_state_are_inverses code = (state_code_by_state . state_by_state_code $ code) == code
+ src/Facts/Geography/Countries/UnitedStates/Address.hs view
@@ -0,0 +1,24 @@+{-#LANGUAGE DeriveDataTypeable #-}+{-#LANGUAGE GeneralizedNewtypeDeriving #-}+module Facts.Geography.Countries.UnitedStates.Address where+ +import Data.Data+import Data.Typeable ++import Facts.Geography.Countries.UnitedStates+import Facts.Geography.Countries.UnitedStates.ZipCode+++data Recipient = Recipient { recipient_name :: String+ , recipient_firm :: Maybe String+ } deriving (Data, Eq, Ord, Show, Typeable)++data Address = Address { recipient :: Recipient+ , street_address :: String + , street_address2 :: Maybe String+ , city :: String+ , state :: Either StateCode OtherUSEntity+ , zip_code :: ZipCode+ } deriving (Data, Eq, Show, Ord, Typeable)++
+ src/Facts/Geography/Countries/UnitedStates/Internal/Data.hs view
@@ -0,0 +1,111 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE TemplateHaskell #-}++module Facts.Geography.Countries.UnitedStates.Internal.Data where++import Data.Data+import Data.Typeable++++-- | The 'State' data type is a list of States in the United States.+data State = Alabama | Alaska | Arizona | Arkansas | California+ | Colorodo | Connecticut | Delaware | Florida | Georgia+ | Hawaii | Idaho | Illinois | Indiana | Iowa+ | Kansas | Kentucky | Louisiana | Maine | Maryland+ | Massachusetts | Michigan | Minnesota | Mississippi | Missouri+ | Montana | Nebraska | Nevada | NewHampshire | NewJersey+ | NewMexico | NewYork | NorthCarolina | NorthDakota | Ohio+ | Oklahoma | Oregon | Pennsylvania | RhodeIsland | SouthCarolina+ | SouthDakota | Tennessee | Texas | Utah | Vermont+ | Virginia | Washington | WestVirginia | Wisconsin | Wyoming+ deriving (Data, Enum, Eq, Ord, Typeable)++-- | State abbreviations:+data StateAbbreviation = AL | AK | AZ | AR | CA | CO | CT | DE | FL | GA+ | HI | ID | IL | IN | IA | KS | KY | LA | ME | MD+ | MA | MI | MN | MS | MO | MT | NE | NV | NH | NJ+ | NM | NY | NC | ND | OH | OK | OR | PA | RI | SC+ | SD | TN | TX | UT | VT | VA | WA | WV | WI | WY+ deriving (Data, Enum, Eq, Ord, Show, Typeable)+++-- | Other US Entities, such as protectorates, districts, and others:+data OtherUSEntity = AmericanSamoa+ | Guam+ | NorthernMarianaIslands+ | PuertoRico+ | USVirginIslands+ | DistrictOfColumbia+ deriving (Data, Eq, Ord, Typeable)++instance Show OtherUSEntity where+ show AmericanSamoa = "American Samoa"+ show Guam = "Guam"+ show NorthernMarianaIslands = "Northern Mariana Islands"+ show PuertoRico = "Puerto Rico"+ show USVirginIslands = "U.S. Virgin Islands"+ show DistrictOfColumbia = "District of Columbia"++++-- | An easy to modify representation of the bijection between 'State's and their+-- 'StateCode's.++states_and_state_codes :: [ (State, StateAbbreviation)]+states_and_state_codes = [ ( Alabama , AL )+ , ( Alaska , AK )+ , ( Arizona , AZ )+ , ( Arkansas , AR )+ , ( California , CA )+ , ( Colorodo , CO )+ , ( Connecticut , CT )+ , ( Delaware , DE )+ , ( Florida , FL )+ , ( Georgia , GA )+ , ( Hawaii , HI )+ , ( Idaho , ID )+ , ( Illinois , IL )+ , ( Indiana , IN )+ , ( Iowa , IA )+ , ( Kansas , KS )+ , ( Kentucky , KY )+ , ( Louisiana , LA )+ , ( Maine , ME )+ , ( Maryland , MD )+ , ( Massachusetts , MA )+ , ( Michigan , MI )+ , ( Minnesota , MN )+ , ( Mississippi , MS )+ , ( Missouri , MO )+ , ( Montana , MT )+ , ( Nebraska , NE )+ , ( Nevada , NV )+ , ( NewHampshire , NH )+ , ( NewJersey , NJ )+ , ( NewMexico , NM )+ , ( NewYork , NY )+ , ( NorthCarolina , NC )+ , ( NorthDakota , ND )+ , ( Ohio , OH )+ , ( Oklahoma , OK )+ , ( Oregon , OR )+ , ( Pennsylvania , PA )+ , ( RhodeIsland , RI )+ , ( SouthCarolina , SC )+ , ( SouthDakota , SD )+ , ( Tennessee , TN )+ , ( Texas , TX )+ , ( Utah , UT )+ , ( Vermont , VT )+ , ( Virginia , VA )+ , ( Washington , WA )+ , ( WestVirginia , WV )+ , ( Wisconsin , WI )+ , ( Wyoming , WY )+ ]
+ src/Facts/Geography/Countries/UnitedStates/Internal/Splices.hs view
@@ -0,0 +1,12 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-} +{-# LANGUAGE TemplateHaskell #-} ++module Facts.Geography.Countries.UnitedStates.Internal.Splices where++import Facts.Geography.Countries.UnitedStates.Internal.Data+import Facts.Utility.Templates++-- | This pair of functions maps states to state abbreviations, and vice-versa.+$( list_to_bijection "state_code_by_state" "state_by_state_code" states_and_state_codes ) +
+ src/Facts/Geography/Countries/UnitedStates/ZipCode.hs view
@@ -0,0 +1,21 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++module Facts.Geography.Countries.UnitedStates.ZipCode where++import Data.Data+import Data.Numerals.Decimal+import Data.Typeable++type Digit = DecimalDigit+ +data ZipCode = ZipCode { zip_code :: (Digit,Digit,Digit,Digit,Digit)+ , plus4 :: Maybe (Digit,Digit,Digit,Digit)+ } deriving (Data, Eq, Ord, Typeable)++instance Show ZipCode where+ show ( ZipCode (z1,z2,z3,z4,z5 ) + (Just (p1,p2,p3,p4) ) ) = (concatMap show [z1,z2,z3,z4,z5])+ ++ " + " + ++ (concatMap show [p1,p2,p3,p4]) + show ( ZipCode (z1,z2,z3,z4,z5) Nothing) = (concatMap show [z1,z2,z3,z4,z5])
+ src/Facts/Geography/Location.hs view
@@ -0,0 +1,61 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-} +{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE TemplateHaskell #-} ++module Facts.Geography.Location ( DMS (..)+ , Elevation (..)+ , Location (..)+ , Latitude (..)+ , Longitude (..)+ ) where++import Data.Angle+import Data.Data+import Data.Typeable++import Facts.Utility.OrphanInstances+++data DMS = DMS { degrees :: Double+ , minutes :: Double+ , seconds :: Double+ } deriving (Data, Eq, Ord, Show, Typeable)+++data Length = Meters Double+ | Feet Double+ deriving (Data, Eq, Ord, Show, Typeable)+++newtype Latitude = Latitude (Degrees Double) deriving (Data, Eq, Ord, Show, Typeable)+newtype Longitude = Longitude (Degrees Double) deriving (Data, Eq, Ord, Show, Typeable)+++-- | Elevation from sea level.+type Elevation = Length+++data Location = Location { latitude :: Latitude+ , longitude :: Longitude+ , elevation :: Maybe Elevation+ } deriving (Data, Eq, Ord, Show, Typeable)++++dms_to_degrees :: DMS -> Degrees Double+dms_to_degrees (DMS d m s) = Degrees (d + m / 60 + s / 3600)++dms_to_latitude :: DMS -> Latitude+dms_to_longitude :: DMS -> Longitude+dms_to_latitude = Latitude . dms_to_degrees+dms_to_longitude = Longitude . dms_to_degrees++dms_lat_long_to_location_at_sea_level :: (DMS, DMS) -> Location+dms_lat_long_to_location_at_sea_level (lat, lon) = Location { latitude = dms_to_latitude $ lat+ , longitude = dms_to_longitude $ lon+ , elevation = Nothing+ }
+ src/Facts/Utility/OrphanInstances.hs view
@@ -0,0 +1,20 @@+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -fwarn-missing-methods #-} +{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveFunctor #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE StandaloneDeriving #-} ++module Facts.Utility.OrphanInstances where++import Data.Angle+import Data.Data+import Data.Typeable++deriving instance Typeable1 Radians+deriving instance Typeable1 Degrees+++deriving instance (Data theta) => Data (Radians theta)+deriving instance (Data theta) => Data (Degrees theta)
+ src/Facts/Utility/Templates.hs view
@@ -0,0 +1,52 @@+module Facts.Utility.Templates ( list_to_bijection+ , list_to_injection+ , list_to_injection_via_pushout+ , list_to_injection_via_pullback+ ) where++import Control.Monad+import Data.Data+import Language.Haskell.TH+import Language.Haskell.TH.Quote+++-- The list must be the list encoding of the extension of a bijective function+list_to_bijection :: (Data a, Data b) => String -> String -> [(a,b)] -> Q [Dec]+list_to_bijection left_name right_name xs = do + m1 <- list_to_injection left_name xs+ m2 <- list_to_injection right_name (adjoint xs)+ return $ m1 ++ m2++-- The list must be the list encoding of the extension of an injective function.+list_to_injection:: (Data a, Data b) => String -> [(a,b)] -> Q [Dec]+list_to_injection name xs = liftM (\x -> [x]) $ liftM (FunD $ mkName name) (mapM mkClause xs)+ where+ mkClause (a,b) = do+ a_pat <- dataToPatQ (const Nothing) a+ b_exp <- dataToExpQ (const Nothing) b+ return $ Clause [a_pat] (NormalB b_exp) []+++-- | Use precomposition to access projections on values in the co-domain. The list must be the extension+-- of an injective function.+list_to_injection_via_pushout :: (Data a, Data b, Data c) => String -> (b -> c) -> [(a,b)] -> Q [Dec]+list_to_injection_via_pushout name f xs = (list_to_injection name) (fmap (apply_right f) xs)++-- | Use precomposition to access injections on values in the domain. The list must be the extension+-- of an injective function. The function by which we pull back must be an injection into the domain.+list_to_injection_via_pullback :: (Data a, Data b, Data c) => String -> (b -> c) -> [(a, b)] -> Q [Dec]+list_to_injection_via_pullback name f xs = (list_to_injection name (adjoint $ fmap (apply_right f) xs)) ++ +flip_pair :: (a, b) -> (b, a)+flip_pair = \(a, b) -> (b, a)+++adjoint :: [(a,b)] -> [(b,a)]+adjoint = fmap flip_pair++apply_left :: (a -> c) -> (a, b) -> (c, b)+apply_left f (a, b) = (f a, b)++apply_right :: (b -> c) -> (a, b) -> (a, c)+apply_right f (a, b) = (a, f b)