Commit 8e903011 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Use `:pkg:fail`'s `MonadFail` class

The `fail` package has been already in lib:Cabal's transitive
dependencies via at least `lib:parsec` (for GHC < 8), so we might
as well depend on it directly and avoid having to deal with two
divergent compat `MonadFail` classes, as well as reduce the amount
of CPP hackery.

This should address the GHC < 8 build failures that were introduced
via c3c29a49

Future work: get rid of internal `Distribution.Compat.MonadFail` module.
parent c3c29a49
......@@ -233,6 +233,10 @@ library
if impl(ghc >= 8.0)
ghc-options: -Wcompat -Wnoncanonical-monad-instances
-Wnoncanonical-monadfail-instances
else
-- at least one of lib:Cabal's dependency (`parsec`)
-- already depends on `fail` transitively
build-depends: fail == 4.9.*
exposed-modules:
Distribution.Backpack
......
{-# LANGUAGE CPP #-}
-- | Compatibility layer for "Control.Monad.Fail"
module Distribution.Compat.MonadFail ( MonadFail(fail) ) where
#if MIN_VERSION_base(4,13,0)
import Prelude (MonadFail(fail))
#elif MIN_VERSION_base(4,9,0)
-- provided by base-4.9.0.0 and later
import Control.Monad.Fail (MonadFail(fail))
#else
-- the following code corresponds to
-- http://hackage.haskell.org/package/fail-4.9.0.0
import qualified Prelude as P
import Distribution.Compat.Prelude hiding (fail)
import Text.ParserCombinators.ReadP
import Text.ParserCombinators.ReadPrec
class Monad m => MonadFail m where
fail :: String -> m a
-- instances provided by base-4.9
instance MonadFail Maybe where
fail _ = Nothing
instance MonadFail [] where
fail _ = []
instance MonadFail P.IO where
fail = P.fail
instance MonadFail ReadPrec where
fail = P.fail -- = P (\_ -> fail s)
instance MonadFail ReadP where
fail = P.fail
#endif
module Distribution.Compat.MonadFail ( Control.Monad.Fail.MonadFail(fail) ) where
import Control.Monad.Fail
......@@ -66,9 +66,7 @@ import Text.PrettyPrint
import qualified Data.Map as Map
#if MIN_VERSION_base(4,9,0)
import qualified Control.Monad.Fail as Fail
#endif
-- -----------------------------------------------------------------------------
......@@ -116,10 +114,8 @@ instance Monad ParseResult where
fail = Fail.fail
#endif
#if MIN_VERSION_base(4,9,0)
instance Fail.MonadFail ParseResult where
fail = parseResultFail
#endif
parseResultFail :: String -> ParseResult a
parseResultFail s = parseFail (FromString s Nothing)
......
......@@ -83,9 +83,7 @@ import Distribution.Client.Compat.Prelude hiding (many, get)
import Control.Monad( replicateM, (>=>) )
#if MIN_VERSION_base(4,9,0)
import qualified Control.Monad.Fail as Fail
#endif
import Distribution.CabalSpecVersion (cabalSpecLatest)
import qualified Distribution.Compat.CharParsing as P
......@@ -130,10 +128,8 @@ instance Monad (P s) where
fail = Fail.fail
#endif
#if MIN_VERSION_base(4,9,0)
instance Fail.MonadFail (P s) where
fail _ = Fail
#endif
instance Alternative (P s) where
empty = mzero
......@@ -197,10 +193,8 @@ instance Monad (Parser r s) where
fail = Fail.fail
#endif
#if MIN_VERSION_base(4,9,0)
instance Fail.MonadFail (Parser r s) where
fail _ = R (const Fail)
#endif
instance s ~ Char => MonadPlus (Parser r s) where
mzero = pfail
......
......@@ -335,6 +335,9 @@ executable cabal
text >= 1.2.3 && < 1.3,
parsec >= 3.1.13.0 && < 3.2
if !impl(ghc >= 8.0)
build-depends: fail == 4.9.*
if flag(native-dns)
if os(windows)
build-depends: windns >= 0.1.0 && < 0.2
......
......@@ -46,6 +46,9 @@ Version: 2.5.0.0
text >= 1.2.3 && < 1.3,
parsec >= 3.1.13.0 && < 3.2
if !impl(ghc >= 8.0)
build-depends: fail == 4.9.*
if flag(native-dns)
if os(windows)
build-depends: windns >= 0.1.0 && < 0.2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment