From 088637b2c04e7b6ba03519578afc211877f050a9 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Thu, 16 May 2019 21:40:19 +0200 Subject: [PATCH] Compat stuff for Monoid / Semigroup --- src/PDF/Output.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/PDF/Output.hs b/src/PDF/Output.hs index 18b7161..d253332 100644 --- a/src/PDF/Output.hs +++ b/src/PDF/Output.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} module PDF.Output ( OBuilder(..) , Output(..) @@ -13,6 +14,9 @@ module PDF.Output ( import Data.ByteString.Builder (Builder, char8, lazyByteString, string8, toLazyByteString) import Data.ByteString.Lazy.Char8 (ByteString) +-- #if MIN_VERSION_base(4,9,0) +-- import qualified Data.Semigroup as Sem +-- #endif import Data.String (IsString(..)) import Control.Monad.Reader (MonadReader(..), Reader, runReader) import qualified PDF.EOL as EOL (Style(..)) @@ -22,9 +26,19 @@ newtype OBuilder = OBuilder (Reader EOL.Style Builder) lift :: (a -> Builder) -> a -> OBuilder lift f a = OBuilder $ return (f a) +append :: OBuilder -> OBuilder -> OBuilder +append (OBuilder a) (OBuilder b) = OBuilder (mappend <$> a <*> b) + +#if MIN_VERSION_base(4,9,0) +instance Semigroup OBuilder where + (<>) = append +#endif + instance Monoid OBuilder where mempty = OBuilder (return mempty) - mappend (OBuilder a) (OBuilder b) = OBuilder (mappend <$> a <*> b) +#if !(MIN_VERSION_base(4,9,0)) + mappend = append +#endif instance IsString OBuilder where fromString = string