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