1 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE QuasiQuotes #-}
4 {-# LANGUAGE TemplateHaskell #-}
5 {-# LANGUAGE TypeFamilies #-}
7 -- | (At least) two different XML types have a notion of locations:
8 -- "TSN.XML.News" and "TSN.XML.Scores". And in fact those two types
9 -- agree on the city, state, and country -- at least for the
10 -- database representation.
12 -- This module contains a data type for the common database
18 -- * WARNING: these are private but exported to silence warnings
19 LocationConstructor(..) )
23 import Data.Tuple.Curry ( uncurryN )
24 import Database.Groundhog () -- Required for some String instance
25 import Database.Groundhog.TH (
29 import Text.XML.HXT.Core (
38 -- | Database representation of a location.
40 -- The country has always been present in the XML that we've
41 -- seen. The city/state however have been observed missing in some
42 -- cases. The Scores are better about always having a city/state,
43 -- but in the interest of consolidation, we've made them optional so
44 -- that they can be mushed together into this one type.
49 state :: Maybe String,
54 -- Generate the Groundhog code for 'Location'.
55 mkPersist defaultCodegenConfig [groundhog|
61 - name: unique_location
63 fields: [city, state, country]
68 -- | We also provide an (un)pickler for one common XML representation,
69 -- used at least in "TSN.XML.News" and "TSN.XML.Location".
71 pickle_location :: PU Location
74 xpWrap (from_tuple, to_tuple) $
75 xpTriple (xpOption (xpElem "city" xpText))
76 (xpOption (xpElem "state" xpText))
77 (xpElem "country" xpText)
79 from_tuple = uncurryN Location
80 to_tuple l = (city l, state l, country l)