diff --git a/doctemplates.cabal b/doctemplates.cabal
--- a/doctemplates.cabal
+++ b/doctemplates.cabal
@@ -1,5 +1,5 @@
 name:                doctemplates
-version:             0.2.1
+version:             0.2.2
 synopsis:            Pandoc-style document templates
 description:         A simple text templating system used by pandoc.
 homepage:            https://github.com/jgm/doctemplates#readme
diff --git a/src/Text/DocTemplates.hs b/src/Text/DocTemplates.hs
--- a/src/Text/DocTemplates.hs
+++ b/src/Text/DocTemplates.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE TypeSynonymInstances, FlexibleInstances,
+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, CPP,
     OverloadedStrings, GeneralizedNewtypeDeriving, ScopedTypeVariables #-}
 {- |
    Module      : Text.Pandoc.Templates
@@ -97,11 +97,18 @@
 import Data.ByteString.Lazy (ByteString, fromChunks)
 import Data.Vector ((!?))
 import Data.Scientific (floatingOrInteger)
+#if MIN_VERSION_base(4,9,0)
+import Data.Semigroup (Semigroup)
+#endif
 
 -- | A 'Template' is essentially a function that takes
 -- a JSON 'Value' and produces 'Text'.
 newtype Template = Template { unTemplate :: Value -> Text }
+#if MIN_VERSION_base(4,9,0)
+                 deriving (Semigroup, Monoid)
+#else
                  deriving Monoid
+#endif
 
 type Variable = [Text]
 
