git.iko.soy/typeable/country-codes
on master help sign in
6 files changed+102−24
since splitsnapshots
unifiedsplit
.gitignore+2 Setup.hs+2 country-codes.cabal+14−5 exe/Main.hs+1−4 src/Data/CountryCodes/ISO31661.hs+71−15 stack.yaml+12
.gitignore+2
@@ -11,3 +11,5 @@ cabal.sandbox.config
1111cabal.config
1212.dist-buildwrapper
1313.project
14+.stack-work
15+*.history
Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
country-codes.cabal+14−5
@@ -1,5 +1,5 @@
11name: country-codes
2−version: 0.1
2+version: 0.1.4
33cabal-version: >= 1.8
44build-type: Simple
55author: JP Moresmau <jpmoresmau@gmail.com>
@@ -29,8 +29,16 @@ library
2929 build-depends:
3030 base >= 4 && < 5
3131 , text >= 0.11
32− , aeson >= 0.5 && < 0.8
33− , shakespeare == 2.0.*
32+ , aeson >= 0.5
33+ , deepseq >= 1.4
34+ , shakespeare
35+ -- == 2.0.*
36+ if !(impl(ghcjs) || arch(javascript) || arch(wasm32))
37+ build-depends:
38+ openapi3
39+ , QuickCheck
40+ , generic-arbitrary
41+ cpp-options: -DBACKEND
3442 ghc-options: -Wall
3543 other-modules: Data.CountryCodes.ISO31661
3644 exposed-modules: Data.CountryCodes
@@ -41,8 +49,9 @@ executable country-codes-generate
4149 build-depends:
4250 base >= 4 && < 5
4351 , text >= 0.11
44− , tagsoup >= 0.13 && < 0.14
45− ghc-options: -Wall -rtsopts
52+ , tagsoup >= 0.13
53+ -- && < 0.15
54+ ghc-options: -Wall -rtsopts
4655 main-is: Main.hs
4756 if !flag(generate)
4857 buildable: False
exe/Main.hs+1−4
@@ -119,10 +119,7 @@ generate assocs =
119119 " | Just a <- fromMText s=pure a" <> nl <>
120120 " parseJSON _ =fail \"CountryCode\"" <> nl <> nl
121121 sp = json <>
122− "-- | show user readable name" <> nl <>
123− "instance ToMessage CountryCode where" <> nl <>
124− " toMessage = toName" <> nl <> nl <>
125− "-- | show user readable name, in english (ignoring locale for now)" <> nl <>
122+ "-- | show user readable name, in English (ignoring locale for now)" <> nl <>
126123 "instance RenderMessage master CountryCode where" <> nl <>
127124 " renderMessage _ _ = toName" <> nl <> nl
128125 in sp
src/Data/CountryCodes/ISO31661.hs+71−15
@@ -1,4 +1,7 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards, FlexibleInstances, MultiParamTypeClasses #-}
1+{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude
2+ , DeriveGeneric, DeriveAnyClass, PatternGuards, FlexibleInstances
3+ , MultiParamTypeClasses, StandaloneDeriving, CPP #-}
4+{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}
25-- | This file is generated from the Wikipedia page
36-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
47module Data.CountryCodes.ISO31661 (
@@ -13,13 +16,20 @@ module Data.CountryCodes.ISO31661 (
1316) where
1417
1518import Control.Applicative (pure)
16−import Data.Aeson
17−import Data.Typeable
18−import qualified Data.Text as T
19−import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail)
20−import Text.Shakespeare.I18N
19+import Control.DeepSeq (NFData(..))
20+import Data.Aeson
21+import Data.Typeable
22+import Data.Text as T
23+import GHC.Generics
24+import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail,seq)
25+import Text.Shakespeare.I18N
26+#ifdef BACKEND
27+import Data.OpenApi
28+import Test.QuickCheck.Arbitrary
29+import Test.QuickCheck.Arbitrary.Generic
30+#endif
2131
22−data CountryCode =
32+data CountryCode =
2333 AD
2434 | AE
2535 | AF
@@ -269,7 +279,19 @@ data CountryCode =
269279 | ZA
270280 | ZM
271281 | ZW
272− deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)
282+ -- Added these non standard codes that occur in
283+ -- travolutionary database
284+ -- https://typeable.atlassian.net/browse/B2H-796
285+ | XA
286+ | AN
287+ | XK
288+ | XC
289+ | WE
290+ deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable, Generic
291+#ifdef BACKEND
292+ , ToSchema
293+#endif
294+ )
273295
274296-- | Maybe get the CountryCode from the text code.
275297fromMText :: T.Text -> Maybe CountryCode
@@ -522,6 +544,11 @@ fromMText "YT" = Just YT
522544fromMText "ZA" = Just ZA
523545fromMText "ZM" = Just ZM
524546fromMText "ZW" = Just ZW
547+fromMText "XA" = Just XA
548+fromMText "AN" = Just AN
549+fromMText "XK" = Just XK
550+fromMText "XC" = Just XC
551+fromMText "WE" = Just WE
525552fromMText _ = Nothing
526553
527554-- | Get the CountryCode from the text code. Errors if the code is unknown
@@ -781,6 +808,11 @@ toText YT = "YT"
781808toText ZA = "ZA"
782809toText ZM = "ZM"
783810toText ZW = "ZW"
811+toText XA = "XA"
812+toText AN = "AN"
813+toText XK = "XK"
814+toText XC = "XC"
815+toText WE = "WE"
784816
785817-- | Maybe get the code from the user readable name.
786818fromMName :: T.Text -> Maybe CountryCode
@@ -1033,6 +1065,11 @@ fromMName "Mayotte" = Just YT
10331065fromMName "South Africa" = Just ZA
10341066fromMName "Zambia" = Just ZM
10351067fromMName "Zimbabwe" = Just ZW
1068+fromMName "Canary Islands" = Just XA
1069+fromMName "Netherlands Antilles" = Just AN
1070+fromMName "Kosovo" = Just XK
1071+fromMName "Ceuta" = Just XC
1072+fromMName "West Bank" = Just WE
10361073fromMName _ = Nothing
10371074
10381075-- | Get the CountryCode from the user readable name. Errors if the name is unknown
@@ -1292,6 +1329,11 @@ toName YT = "Mayotte"
12921329toName ZA = "South Africa"
12931330toName ZM = "Zambia"
12941331toName ZW = "Zimbabwe"
1332+toName XA = "Canary Islands"
1333+toName AN = "Netherlands Antilles"
1334+toName XK = "Kosovo"
1335+toName XC = "Ceuta"
1336+toName WE = "West Bank"
12951337
12961338-- | list of names sorted by alphabetical order, with country code
12971339-- this is ready to be used in a yesod selectField, for example
@@ -1544,23 +1586,37 @@ countryList = [("Afghanistan",AF)
15441586 ,("Yemen",YE)
15451587 ,("Zambia",ZM)
15461588 ,("Zimbabwe",ZW)
1547− ,("Åland Islands",AX) ]
1589+ ,("Åland Islands",AX)
1590+ ,("Canary Islands", XA)
1591+ ,("Netherlands Antilles",AN)
1592+ ,("Kosovo",XK)
1593+ ,("Ceuta",XC)
1594+ ,("West Bank",WE)
1595+ ]
15481596
15491597-- | to json: as a simple string
15501598instance ToJSON CountryCode where
1551− toJSON =toJSON . toText
1599+ toJSON = toJSON . toText
15521600
15531601-- | from json: as a simple string
15541602instance FromJSON CountryCode where
15551603 parseJSON (String s)
15561604 | Just a <- fromMText s=pure a
1557− parseJSON _ =fail "CountryCode"
1605+ parseJSON _ = fail "CountryCode"
15581606
1559−-- | show user readable name
1560−instance ToMessage CountryCode where
1561− toMessage = toName
1607+deriving instance ToJSONKey CountryCode
1608+deriving instance FromJSONKey CountryCode
15621609
1563−-- | show user readable name, in english (ignoring locale for now)
1610+-- | show user readable name, in English (ignoring locale for now)
15641611instance RenderMessage master CountryCode where
15651612 renderMessage _ _ = toName
15661613
1614+-- | Allow the deep evaluation of CountryCode with `deepseq`
1615+instance NFData CountryCode where
1616+ rnf a = a `seq` ()
1617+
1618+#ifdef BACKEND
1619+instance Arbitrary CountryCode where
1620+ arbitrary = genericArbitrary
1621+ shrink = genericShrink
1622+#endif
stack.yamlnew file+12
@@ -0,0 +1,12 @@
1+resolver: lts-21.3
2+
3+packages:
4+- .
5+
6+# extra-deps:
7+# - git: https://github.com/typeable/openapi3.git
8+# # nix-sha256: 1aqn5dia4aqwpmr3v0rcb8kzhknp5674hhay8h7p76206dx83ykg
9+# commit: bb1c64f8501535143c92907166fdc9f8df6d51b9
10+# - git: https://github.com/typeable/generic-arbitrary.git
11+# # nix-sha256: 01k87zxa8cd5ssy1wiqwyqqvz4v7lvh3q6cipmadg4w2ynmfbdn0
12+# commit: 84c62a4de517c78e5080f5451714ce7944987ba6