@@ -31,6 +31,10 @@ import Control.Applicative (Alternative(..))
3131import Streamly.Internal.Data.Zipper (Zipper)
3232import qualified Streamly.Internal.Data.Zipper as Z
3333
34+#if MIN_VERSION_base(4,9,0)
35+import qualified Control.Monad.Fail as Fail
36+#endif
37+
3438newtype Parser m a b =
3539 MkParser { runParser :: forall r.
3640 Zipper m a -> ((Zipper m a, Either String b) -> m r) -> m r }
@@ -140,6 +144,19 @@ instance Monad m => Monad (Parser m a) where
140144 Left err -> runParser (die err) z yieldk
141145 in runParser m inp yield1
142146
147+#if !(MIN_VERSION_base(4,13,0))
148+ -- This is redefined instead of just being Fail.fail to be
149+ -- compatible with base 4.8.
150+ {-# INLINE fail #-}
151+ fail = die
152+#endif
153+
154+#if MIN_VERSION_base(4,9,0)
155+instance Monad m => Fail.MonadFail (Parser m a) where
156+ {-# INLINE fail #-}
157+ fail = die
158+#endif
159+
143160-- | 'Alternative' form of 'Streamly.Internal.Data.Parser.alt'. Backtrack and
144161-- run the second parser if the first one fails.
145162--