From 000627c94a4d4aedb0a4216e781f6af65936ef9c Mon Sep 17 00:00:00 2001 From: Christian Barcenas Date: Sun, 11 Feb 2018 03:22:28 -0800 Subject: Add Semigroup instances for existing Monoids Ensures forwards compatibility with future Haskell/GHC releases as the Semigroup/Monoid Proposal is gradually implemented. Closes #525 and #536. --- lib/Hakyll/Core/Rules/Internal.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/Hakyll/Core/Rules') diff --git a/lib/Hakyll/Core/Rules/Internal.hs b/lib/Hakyll/Core/Rules/Internal.hs index 0641dcf..647af74 100644 --- a/lib/Hakyll/Core/Rules/Internal.hs +++ b/lib/Hakyll/Core/Rules/Internal.hs @@ -1,4 +1,5 @@ -------------------------------------------------------------------------------- +{-# LANGUAGE CPP #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE Rank2Types #-} module Hakyll.Core.Rules.Internal @@ -16,6 +17,9 @@ import Control.Monad.Reader (ask) import Control.Monad.RWS (RWST, runRWST) import Control.Monad.Trans (liftIO) import qualified Data.Map as M +#if MIN_VERSION_base(4,9,0) +import Data.Semigroup (Semigroup (..)) +#endif import Data.Set (Set) @@ -52,10 +56,20 @@ data RuleSet = RuleSet -------------------------------------------------------------------------------- +#if MIN_VERSION_base(4,9,0) +instance Semigroup RuleSet where + (<>) (RuleSet r1 c1 s1 p1) (RuleSet r2 c2 s2 p2) = + RuleSet (mappend r1 r2) (mappend c1 c2) (mappend s1 s2) (p1 .||. p2) + +instance Monoid RuleSet where + mempty = RuleSet mempty mempty mempty mempty + mappend = (<>) +#else instance Monoid RuleSet where mempty = RuleSet mempty mempty mempty mempty mappend (RuleSet r1 c1 s1 p1) (RuleSet r2 c2 s2 p2) = RuleSet (mappend r1 r2) (mappend c1 c2) (mappend s1 s2) (p1 .||. p2) +#endif -------------------------------------------------------------------------------- -- cgit v1.2.3