From bc55e1c58fab8c62f91cf37eb10306219de3d8ec Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 2 Sep 2025 08:18:09 +0100 Subject: [PATCH] dev: fix liftA2, Foldable1 build errors with ghc <9.6 [#2395] --- hledger-lib/Hledger/Data/PeriodData.hs | 6 ++++++ hledger-lib/Hledger/Reports/MultiBalanceReport.hs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/hledger-lib/Hledger/Data/PeriodData.hs b/hledger-lib/Hledger/Data/PeriodData.hs index 13741163d..78032a2b9 100644 --- a/hledger-lib/Hledger/Data/PeriodData.hs +++ b/hledger-lib/Hledger/Data/PeriodData.hs @@ -19,7 +19,11 @@ module Hledger.Data.PeriodData , tests_PeriodData ) where +#if MIN_VERSION_base(4,18,0) import Data.Foldable1 (Foldable1(..)) +#else +import Control.Applicative (liftA2) +#endif import qualified Data.IntMap.Strict as IM import qualified Data.IntSet as IS #if !MIN_VERSION_base(4,20,0) @@ -48,10 +52,12 @@ instance Foldable PeriodData where foldl f z (PeriodData h as) = foldl f (f z h) as foldl' f z (PeriodData h as) = let fzh = f z h in fzh `seq` foldl' f fzh as +#if MIN_VERSION_base(4,18,0) instance Foldable1 PeriodData where foldrMap1 f g (PeriodData h as) = foldr g (f h) as foldlMap1 f g (PeriodData h as) = foldl g (f h) as foldlMap1' f g (PeriodData h as) = let fh = f h in fh `seq` foldl' g fh as +#endif instance Traversable PeriodData where traverse f (PeriodData h as) = liftA2 PeriodData (f h) $ traverse f as diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs index 1e95b83aa..6f05cd061 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE NamedFieldPuns #-} @@ -33,6 +34,9 @@ module Hledger.Reports.MultiBalanceReport ( ) where +#if !MIN_VERSION_base(4,18,0) +import Control.Applicative (liftA2) +#endif import Control.Monad (guard) import Data.Foldable (toList) import Data.List (sortOn)