From: Michael Orlitzky Date: Mon, 29 Dec 2014 21:32:59 +0000 (-0500) Subject: Use Generics.to_tuple in TSN.XML.AutoRacingDriverList. X-Git-Tag: 0.2.1~58 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=bd8a41c76ed405f06c09e2594bcec37e85d51e22;p=dead%2Fhtsn-import.git Use Generics.to_tuple in TSN.XML.AutoRacingDriverList. --- diff --git a/src/TSN/XML/AutoRacingDriverList.hs b/src/TSN/XML/AutoRacingDriverList.hs index 327c358..b1a611e 100644 --- a/src/TSN/XML/AutoRacingDriverList.hs +++ b/src/TSN/XML/AutoRacingDriverList.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE QuasiQuotes #-} @@ -36,6 +37,7 @@ import Database.Groundhog.Sqlite ( withSqliteConn ) import Database.Groundhog.TH ( groundhog, mkPersist ) +import qualified GHC.Generics as GHC ( Generic ) import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) import Text.XML.HXT.Core ( @@ -50,6 +52,7 @@ import Text.XML.HXT.Core ( xpWrap ) -- Local imports. +import Generics ( Generic(..), to_tuple ) import TSN.Codegen ( tsn_codegen_config ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_date, xp_time_stamp ) @@ -101,7 +104,11 @@ data Message = xml_title :: String, xml_listings :: [AutoRacingDriverListListingXml], xml_time_stamp :: UTCTime } - deriving (Eq, Show) + deriving (Eq, GHC.Generic, Show) + +-- | For 'Generics.to_tuple'. +-- +instance Generic Message instance ToDb Message where @@ -165,8 +172,11 @@ data AutoRacingDriverListListingXml = xml_nationality :: Maybe String, xml_car_number :: Int, xml_car :: String } - deriving (Eq, Show) + deriving (Eq, GHC.Generic, Show) +-- | For 'Generics.to_tuple'. +-- +instance Generic AutoRacingDriverListListingXml instance ToDb AutoRacingDriverListListingXml where -- | The database analogue of an 'AutoRacingDriverListListingXml' is @@ -272,15 +282,6 @@ pickle_listing = (xpElem "Car" xpText) where from_tuple = uncurryN AutoRacingDriverListListingXml - to_tuple m = (xml_driver_id m, - xml_driver m, - xml_height m, - xml_weight m, - xml_date_of_birth m, - xml_hometown m, - xml_nationality m, - xml_car_number m, - xml_car m) -- | Pickler for the top-level 'Message'. -- @@ -297,13 +298,6 @@ pickle_message = (xpElem "time_stamp" xp_time_stamp) where from_tuple = uncurryN Message - to_tuple m = (xml_xml_file_id m, - xml_heading m, - xml_category m, - xml_sport m, - xml_title m, - xml_listings m, - xml_time_stamp m)