hledger-lib: add missing Semigroup instance for Journal
GHC 8.4.1 makes Semigroup a superclass of Monoid. See https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid for details.
This commit is contained in:
parent
61f7563fa2
commit
4c5a58ec1e
@ -1,5 +1,7 @@
|
|||||||
{-# LANGUAGE Rank2Types #-}
|
{-# LANGUAGE Rank2Types #-}
|
||||||
{-# LANGUAGE StandaloneDeriving, OverloadedStrings #-}
|
{-# LANGUAGE StandaloneDeriving, OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
A 'Journal' is a set of transactions, plus optional related data. This is
|
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.Maybe
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
|
import qualified Data.Semigroup as Sem
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Safe (headMay, headDef)
|
import Safe (headMay, headDef)
|
||||||
@ -159,9 +162,8 @@ instance Show Journal where
|
|||||||
-- CHILD <> PARENT. A parsed journal's data is in reverse order, so
|
-- CHILD <> PARENT. A parsed journal's data is in reverse order, so
|
||||||
-- this gives what we want.
|
-- this gives what we want.
|
||||||
--
|
--
|
||||||
instance Monoid Journal where
|
instance Sem.Semigroup Journal where
|
||||||
mempty = nulljournal
|
j1 <> j2 = Journal {
|
||||||
mappend j1 j2 = Journal {
|
|
||||||
jparsedefaultyear = jparsedefaultyear j2
|
jparsedefaultyear = jparsedefaultyear j2
|
||||||
,jparsedefaultcommodity = jparsedefaultcommodity j2
|
,jparsedefaultcommodity = jparsedefaultcommodity j2
|
||||||
,jparseparentaccounts = jparseparentaccounts j2
|
,jparseparentaccounts = jparseparentaccounts j2
|
||||||
@ -180,6 +182,13 @@ instance Monoid Journal where
|
|||||||
,jlastreadtime = max (jlastreadtime j1) (jlastreadtime j2)
|
,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
|
||||||
nulljournal = Journal {
|
nulljournal = Journal {
|
||||||
jparsedefaultyear = Nothing
|
jparsedefaultyear = Nothing
|
||||||
|
|||||||
@ -84,6 +84,8 @@ library
|
|||||||
, transformers >=0.2
|
, transformers >=0.2
|
||||||
, uglymemo
|
, uglymemo
|
||||||
, utf8-string >=0.3.5
|
, utf8-string >=0.3.5
|
||||||
|
if !impl(ghc >= 8.0)
|
||||||
|
build-depends: semigroups == 0.18.*
|
||||||
exposed-modules:
|
exposed-modules:
|
||||||
Hledger
|
Hledger
|
||||||
Hledger.Data
|
Hledger.Data
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user