From 0f752eca113a333ee7ffe7e614cfba7ec74807c0 Mon Sep 17 00:00:00 2001
From: Herbert Valerio Riedel <hvr@gnu.org>
Date: Mon, 21 Jan 2019 00:42:48 +0100
Subject: [PATCH] Compatibility with future ghc-8.8/base-4.13

---
 src/Data/Binary/Class.hs        |  2 +-
 src/Data/Binary/Get/Internal.hs | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/Data/Binary/Class.hs b/src/Data/Binary/Class.hs
index 51e184f..0f4917d 100644
--- a/src/Data/Binary/Class.hs
+++ b/src/Data/Binary/Class.hs
@@ -974,7 +974,7 @@ putTypeRep (Fun arg res) = do
     put (3 :: Word8)
     putTypeRep arg
     putTypeRep res
-putTypeRep _ = fail "GHCi.TH.Binary.putTypeRep: Impossible"
+putTypeRep _ = error "GHCi.TH.Binary.putTypeRep: Impossible"
 
 getSomeTypeRep :: Get SomeTypeRep
 getSomeTypeRep = do
diff --git a/src/Data/Binary/Get/Internal.hs b/src/Data/Binary/Get/Internal.hs
index c2ebcff..a469cbe 100644
--- a/src/Data/Binary/Get/Internal.hs
+++ b/src/Data/Binary/Get/Internal.hs
@@ -91,12 +91,20 @@ type Success a r = B.ByteString -> a -> Decoder r
 instance Monad Get where
   return = pure
   (>>=) = bindG
-#if MIN_VERSION_base(4,9,0)
-  fail = Fail.fail
+#if !(MIN_VERSION_base(4,9,0))
+  fail = failG -- base < 4.9
+#elif !(MIN_VERSION_base(4,13,0))
+  fail = Fail.fail -- base < 4.13
+#endif
+-- NB: Starting with base-4.13, the `fail` method
+--     has been removed from the `Monad`-class
+--     according to the MonadFail proposal (MFP) schedule
+--     which completes the process that started with base-4.9.
 
+#if MIN_VERSION_base(4,9,0)
 instance Fail.MonadFail Get where
-#endif
   fail = failG
+#endif
 
 bindG :: Get a -> (a -> Get b) -> Get b
 bindG (C c) f = C $ \i ks -> c i (\i' a -> (runCont (f a)) i' ks)
-- 
GitLab