From: Michael Orlitzky Date: Mon, 29 Dec 2014 21:34:59 +0000 (-0500) Subject: Use Generics.to_tuple in TSN.XML.Heartbeat. X-Git-Tag: 0.2.1~54 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=071f8f23b010afab6ab916c480035753c82fc962;p=dead%2Fhtsn-import.git Use Generics.to_tuple in TSN.XML.Heartbeat. --- diff --git a/src/TSN/XML/Heartbeat.hs b/src/TSN/XML/Heartbeat.hs index 8fafba1..b44f930 100644 --- a/src/TSN/XML/Heartbeat.hs +++ b/src/TSN/XML/Heartbeat.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Handle documents defined by Heartbeat.dtd. @@ -12,6 +13,7 @@ where -- System imports. import Data.Time.Clock ( UTCTime ) import Data.Tuple.Curry ( uncurryN ) +import qualified GHC.Generics as GHC ( Generic ) import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) import Text.XML.HXT.Core ( @@ -25,6 +27,7 @@ import Text.XML.HXT.Core ( xpWrap ) -- Local imports. +import Generics ( Generic(..), to_tuple ) import TSN.DbImport ( ImportResult(..) ) import TSN.Picklers ( xp_time_stamp ) import Xml ( pickle_unpickle, unpickleable ) @@ -39,11 +42,15 @@ dtd = "Heartbeat.dtd" -- Heartbeat message. -- data Message = - Message { - xml_file_id :: Int, - heading :: String, - time_stamp :: UTCTime } - deriving (Eq, Show) + Message + Int -- xml_file_id + String -- heading + UTCTime -- time_stamp + deriving (Eq, GHC.Generic, Show) + +-- | For 'Generics.to_tuple'. +-- +instance Generic Message -- | A (un)pickler that turns a Heartbeat XML file into a 'Message' @@ -58,9 +65,6 @@ pickle_message = (xpElem "time_stamp" xp_time_stamp) where from_tuple = uncurryN Message - to_tuple m = (xml_file_id m, - heading m, - time_stamp m) -- | Verify (and report) the received heartbeat. We return