make most types instances of Data (and Typeable)

This allows them to be pretty-printed with pprint (from data-pprint)
when debugging, and shouldn't have much impact otherwise.
This commit is contained in:
Simon Michael 2013-12-06 13:19:43 -08:00
parent 8857366854
commit 22a8020296
2 changed files with 24 additions and 19 deletions

View File

@ -1,4 +1,4 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
{-|
Most data types are defined here to avoid import cycles.
@ -24,7 +24,7 @@ import Data.Data
import qualified Data.Map as M
import Data.Time.Calendar
import Data.Time.LocalTime
import System.Time (ClockTime)
import System.Time (ClockTime(..))
type SmartDate = (String,String,String)
@ -41,7 +41,7 @@ data Interval = NoInterval
type AccountName = String
data Side = L | R deriving (Eq,Show,Read,Ord)
data Side = L | R deriving (Eq,Show,Read,Ord,Typeable,Data)
type Commodity = String
@ -49,7 +49,7 @@ type Quantity = Double
-- | An amount's price (none, per unit, or total) in another commodity.
-- Note the price should be a positive number, although this is not enforced.
data Price = NoPrice | UnitPrice Amount | TotalPrice Amount deriving (Eq,Ord)
data Price = NoPrice | UnitPrice Amount | TotalPrice Amount deriving (Eq,Ord,Typeable,Data)
-- | Display style for an amount.
data AmountStyle = AmountStyle {
@ -59,19 +59,19 @@ data AmountStyle = AmountStyle {
asdecimalpoint :: Char, -- ^ character used as decimal point
asseparator :: Char, -- ^ character used for separating digit groups (eg thousands)
asseparatorpositions :: [Int] -- ^ positions of digit group separators, counting leftward from decimal point
} deriving (Eq,Ord,Show,Read)
} deriving (Eq,Ord,Read,Show,Typeable,Data)
data Amount = Amount {
acommodity :: Commodity,
aquantity :: Quantity,
aprice :: Price, -- ^ the (fixed) price for this amount, if any
astyle :: AmountStyle
} deriving (Eq,Ord)
} deriving (Eq,Ord,Typeable,Data)
newtype MixedAmount = Mixed [Amount] deriving (Eq,Ord)
newtype MixedAmount = Mixed [Amount] deriving (Eq,Ord,Typeable,Data)
data PostingType = RegularPosting | VirtualPosting | BalancedVirtualPosting
deriving (Eq,Show)
deriving (Eq,Show,Typeable,Data)
type Tag = (String, String) -- ^ A tag name and (possibly empty) value.
@ -87,7 +87,7 @@ data Posting = Posting {
pbalanceassertion :: Maybe MixedAmount, -- ^ optional: the expected balance in the account after this posting
ptransaction :: Maybe Transaction -- ^ this posting's parent transaction (co-recursive types).
-- Tying this knot gets tedious, Maybe makes it easier/optional.
}
} deriving (Typeable,Data)
-- The equality test for postings ignores the parent transaction's
-- identity, to avoid infinite loops.
@ -104,31 +104,31 @@ data Transaction = Transaction {
ttags :: [Tag], -- ^ tag names and values, extracted from the comment
tpostings :: [Posting], -- ^ this transaction's postings
tpreceding_comment_lines :: String -- ^ any comment lines immediately preceding this transaction
} deriving (Eq)
} deriving (Eq,Typeable,Data)
data ModifierTransaction = ModifierTransaction {
mtvalueexpr :: String,
mtpostings :: [Posting]
} deriving (Eq)
} deriving (Eq,Typeable,Data)
data PeriodicTransaction = PeriodicTransaction {
ptperiodicexpr :: String,
ptpostings :: [Posting]
} deriving (Eq)
} deriving (Eq,Typeable,Data)
data TimeLogCode = SetBalance | SetRequiredHours | In | Out | FinalOut deriving (Eq,Ord)
data TimeLogCode = SetBalance | SetRequiredHours | In | Out | FinalOut deriving (Eq,Ord,Typeable,Data)
data TimeLogEntry = TimeLogEntry {
tlcode :: TimeLogCode,
tldatetime :: LocalTime,
tlcomment :: String
} deriving (Eq,Ord)
} deriving (Eq,Ord,Typeable,Data)
data HistoricalPrice = HistoricalPrice {
hdate :: Day,
hcommodity :: Commodity,
hamount :: Amount
} deriving (Eq) -- & Show (in Amount.hs)
} deriving (Eq,Typeable,Data) -- & Show (in Amount.hs)
type Year = Integer
@ -143,7 +143,10 @@ data JournalContext = Ctx {
-- specified with "account" directive(s). Concatenated, these
-- are the account prefix prepended to parsed account names.
, ctxAliases :: ![(AccountName,AccountName)] -- ^ the current list of account name aliases in effect
} deriving (Read, Show, Eq)
} deriving (Read, Show, Eq, Data, Typeable)
deriving instance Data (ClockTime)
deriving instance Typeable (ClockTime)
data Journal = Journal {
jmodifiertxns :: [ModifierTransaction],
@ -159,7 +162,7 @@ data Journal = Journal {
-- order encountered (XXX reversed, cf journalAddFile).
filereadtime :: ClockTime, -- ^ when this journal was last read from its file(s)
jcommoditystyles :: M.Map Commodity AmountStyle -- ^ how to display amounts in each commodity
} deriving (Eq, Typeable)
} deriving (Eq, Typeable, Data)
-- | A JournalUpdate is some transformation of a Journal. It can do I/O or
-- raise an error.

View File

@ -1,3 +1,4 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-|
A general query system for matching things (accounts, postings,
@ -32,6 +33,7 @@ module Hledger.Query (
tests_Hledger_Query
)
where
import Data.Data
import Data.Either
import Data.List
import Data.Maybe
@ -70,7 +72,7 @@ data Query = Any -- ^ always match
| Depth Int -- ^ match if account depth is less than or equal to this value
| Tag String (Maybe String) -- ^ match if a tag with this exact name, and with value
-- matching the regexp if provided, exists
deriving (Eq)
deriving (Eq,Data,Typeable)
-- custom Show implementation to show strings more accurately, eg for debugging regexps
instance Show Query where
@ -97,7 +99,7 @@ data QueryOpt = QueryOptInAcctOnly AccountName -- ^ show an account register fo
| QueryOptInAcct AccountName -- ^ as above but include sub-accounts in the account register
-- | QueryOptCostBasis -- ^ show amounts converted to cost where possible
-- | QueryOptDate2 -- ^ show secondary dates instead of primary dates
deriving (Show, Eq)
deriving (Show, Eq, Data, Typeable)
-- parsing