diff options
author | Christian Barcenas <christian@cbarcenas.com> | 2018-02-11 03:22:28 -0800 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2018-03-13 15:17:22 +0100 |
commit | 000627c94a4d4aedb0a4216e781f6af65936ef9c (patch) | |
tree | 5e450aa70633a37b3fda41cf8aa3d0c77379b790 /lib/Hakyll/Core/Routes.hs | |
parent | 157fef58b97527b05b0400ad98d9cbdd2a33a0f4 (diff) | |
download | hakyll-000627c94a4d4aedb0a4216e781f6af65936ef9c.tar.gz |
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.
Diffstat (limited to 'lib/Hakyll/Core/Routes.hs')
-rw-r--r-- | lib/Hakyll/Core/Routes.hs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Hakyll/Core/Routes.hs b/lib/Hakyll/Core/Routes.hs index 513725f..06bf633 100644 --- a/lib/Hakyll/Core/Routes.hs +++ b/lib/Hakyll/Core/Routes.hs @@ -25,6 +25,7 @@ -- not appear in your site directory. -- -- * If an item matches multiple routes, the first rule will be chosen. +{-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-} module Hakyll.Core.Routes ( UsedMetadata @@ -42,6 +43,9 @@ module Hakyll.Core.Routes -------------------------------------------------------------------------------- +#if MIN_VERSION_base(4,9,0) +import Data.Semigroup (Semigroup (..)) +#endif import System.FilePath (replaceExtension) @@ -74,6 +78,18 @@ newtype Routes = Routes -------------------------------------------------------------------------------- +#if MIN_VERSION_base(4,9,0) +instance Semigroup Routes where + (<>) (Routes f) (Routes g) = Routes $ \p id' -> do + (mfp, um) <- f p id' + case mfp of + Nothing -> g p id' + Just _ -> return (mfp, um) + +instance Monoid Routes where + mempty = Routes $ \_ _ -> return (Nothing, False) + mappend = (<>) +#else instance Monoid Routes where mempty = Routes $ \_ _ -> return (Nothing, False) mappend (Routes f) (Routes g) = Routes $ \p id' -> do @@ -81,6 +97,7 @@ instance Monoid Routes where case mfp of Nothing -> g p id' Just _ -> return (mfp, um) +#endif -------------------------------------------------------------------------------- |