From d2ee5b2b0eb2afb970ab8d4feed84434dc8236e0 Mon Sep 17 00:00:00 2001 From: Veronika Romashkina Date: Wed, 26 Feb 2020 10:49:03 +0000 Subject: Support GHC-8.8 Add MonadFail instances and constraints. --- lib/Hakyll/Core/Compiler/Internal.hs | 8 +++++++- lib/Hakyll/Core/Metadata.hs | 2 +- lib/Hakyll/Core/Rules/Internal.hs | 2 +- lib/Hakyll/Web/Template/Context.hs | 2 +- lib/Hakyll/Web/Template/List.hs | 8 ++++---- 5 files changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Hakyll/Core/Compiler/Internal.hs b/lib/Hakyll/Core/Compiler/Internal.hs index 762630c..3b62e2d 100644 --- a/lib/Hakyll/Core/Compiler/Internal.hs +++ b/lib/Hakyll/Core/Compiler/Internal.hs @@ -40,6 +40,7 @@ module Hakyll.Core.Compiler.Internal import Control.Applicative (Alternative (..)) import Control.Exception (SomeException, handle) import Control.Monad (forM_) +import qualified Control.Monad.Fail as Fail import Control.Monad.Except (MonadError (..)) import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NonEmpty @@ -183,9 +184,14 @@ instance Monad Compiler where CompilerError e -> return $ CompilerError e {-# INLINE (>>=) #-} - fail = compilerThrow . return +#if !(MIN_VERSION_base(4,13,0)) + fail = Fail.fail {-# INLINE fail #-} +#endif +instance Fail.MonadFail Compiler where + fail = compilerThrow . return + {-# INLINE fail #-} -------------------------------------------------------------------------------- instance Applicative Compiler where diff --git a/lib/Hakyll/Core/Metadata.hs b/lib/Hakyll/Core/Metadata.hs index 1cf536e..9d99857 100644 --- a/lib/Hakyll/Core/Metadata.hs +++ b/lib/Hakyll/Core/Metadata.hs @@ -66,7 +66,7 @@ getMetadataField identifier key = do -------------------------------------------------------------------------------- -- | Version of 'getMetadataField' which throws an error if the field does not -- exist. -getMetadataField' :: MonadMetadata m => Identifier -> String -> m String +getMetadataField' :: (MonadFail m, MonadMetadata m) => Identifier -> String -> m String getMetadataField' identifier key = do field <- getMetadataField identifier key case field of diff --git a/lib/Hakyll/Core/Rules/Internal.hs b/lib/Hakyll/Core/Rules/Internal.hs index 647af74..2617798 100644 --- a/lib/Hakyll/Core/Rules/Internal.hs +++ b/lib/Hakyll/Core/Rules/Internal.hs @@ -88,7 +88,7 @@ emptyRulesState = RulesState Nothing Nothing -- | The monad used to compose rules newtype Rules a = Rules { unRules :: RWST RulesRead RuleSet RulesState IO a - } deriving (Monad, Functor, Applicative) + } deriving (Monad, MonadFail, Functor, Applicative) -------------------------------------------------------------------------------- diff --git a/lib/Hakyll/Web/Template/Context.hs b/lib/Hakyll/Web/Template/Context.hs index 8627d5b..a5049c2 100644 --- a/lib/Hakyll/Web/Template/Context.hs +++ b/lib/Hakyll/Web/Template/Context.hs @@ -365,7 +365,7 @@ dateFieldWith locale key format = field key $ \i -> do -- | Parser to try to extract and parse the time from the @published@ -- field or from the filename. See 'dateField' for more information. -- Exported for user convenience. -getItemUTC :: MonadMetadata m +getItemUTC :: (MonadMetadata m, MonadFail m) => TimeLocale -- ^ Output time locale -> Identifier -- ^ Input page -> m UTCTime -- ^ Parsed UTCTime diff --git a/lib/Hakyll/Web/Template/List.hs b/lib/Hakyll/Web/Template/List.hs index 4d769fc..db3fff1 100644 --- a/lib/Hakyll/Web/Template/List.hs +++ b/lib/Hakyll/Web/Template/List.hs @@ -60,7 +60,7 @@ applyJoinTemplateList delimiter tpl context items = do -------------------------------------------------------------------------------- -- | Sort pages chronologically. Uses the same method as 'dateField' for -- extracting the date. -chronological :: MonadMetadata m => [Item a] -> m [Item a] +chronological :: (MonadMetadata m, MonadFail m) => [Item a] -> m [Item a] chronological = sortByM $ getItemUTC defaultTimeLocale . itemIdentifier where @@ -71,14 +71,14 @@ chronological = -------------------------------------------------------------------------------- -- | The reverse of 'chronological' -recentFirst :: MonadMetadata m => [Item a] -> m [Item a] +recentFirst :: (MonadMetadata m, MonadFail m) => [Item a] -> m [Item a] recentFirst = liftM reverse . chronological -------------------------------------------------------------------------------- -- | Version of 'chronological' which doesn't need the actual items. sortChronological - :: MonadMetadata m => [Identifier] -> m [Identifier] + :: (MonadMetadata m, MonadFail m) => [Identifier] -> m [Identifier] sortChronological ids = liftM (map itemIdentifier) $ chronological [Item i () | i <- ids] @@ -86,6 +86,6 @@ sortChronological ids = -------------------------------------------------------------------------------- -- | Version of 'recentFirst' which doesn't need the actual items. sortRecentFirst - :: MonadMetadata m => [Identifier] -> m [Identifier] + :: (MonadMetadata m, MonadFail m) => [Identifier] -> m [Identifier] sortRecentFirst ids = liftM (map itemIdentifier) $ recentFirst [Item i () | i <- ids] -- cgit v1.2.3