diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index f0445316d..6a65250ab 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -1,5 +1,7 @@ {-# LANGUAGE Rank2Types #-} {-# LANGUAGE StandaloneDeriving, OverloadedStrings #-} +{-# LANGUAGE CPP #-} + {-| A 'Journal' is a set of transactions, plus optional related data. This is @@ -84,6 +86,7 @@ import Data.List.Extra (groupSort) import Data.Maybe import Data.Monoid import Data.Ord +import qualified Data.Semigroup as Sem import Data.Text (Text) import qualified Data.Text as T import Safe (headMay, headDef) @@ -159,9 +162,8 @@ instance Show Journal where -- CHILD <> PARENT. A parsed journal's data is in reverse order, so -- this gives what we want. -- -instance Monoid Journal where - mempty = nulljournal - mappend j1 j2 = Journal { +instance Sem.Semigroup Journal where + j1 <> j2 = Journal { jparsedefaultyear = jparsedefaultyear j2 ,jparsedefaultcommodity = jparsedefaultcommodity j2 ,jparseparentaccounts = jparseparentaccounts j2 @@ -180,6 +182,13 @@ instance Monoid Journal where ,jlastreadtime = max (jlastreadtime j1) (jlastreadtime j2) } +instance Monoid Journal where + mempty = nulljournal +#if !(MIN_VERSION_base(4,11,0)) + -- This is redundant starting with base-4.11 / GHC 8.4. + mappend = (Sem.<>) +#endif + nulljournal :: Journal nulljournal = Journal { jparsedefaultyear = Nothing diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 90c7194a2..1a9e20f80 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -84,6 +84,8 @@ library , transformers >=0.2 , uglymemo , utf8-string >=0.3.5 + if !impl(ghc >= 8.0) + build-depends: semigroups == 0.18.* exposed-modules: Hledger Hledger.Data