on master help sign in
Add MonadFail instance for Parser.
e0a95b5pranaysashank
src/Streamly/Internal/Data/Parser/ParserK/Types.hs+17
@@ -31,6 +31,10 @@ import Control.Applicative (Alternative(..))
31import Streamly.Internal.Data.Zipper (Zipper)
31import Streamly.Internal.Data.Zipper (Zipper)
32import qualified Streamly.Internal.Data.Zipper as Z
32import qualified Streamly.Internal.Data.Zipper as Z
33
33
34+#if MIN_VERSION_base(4,9,0)
35+import qualified Control.Monad.Fail as Fail
36+#endif
37+
34newtype Parser m a b =
38newtype Parser m a b =
35 MkParser { runParser :: forall r.
39 MkParser { runParser :: forall r.
36 Zipper m a -> ((Zipper m a, Either String b) -> m r) -> m r }
40 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
140 Left err -> runParser (die err) z yieldk
144 Left err -> runParser (die err) z yieldk
141 in runParser m inp yield1
145 in runParser m inp yield1
142
146
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+
143-- | 'Alternative' form of 'Streamly.Internal.Data.Parser.alt'. Backtrack and
160-- | 'Alternative' form of 'Streamly.Internal.Data.Parser.alt'. Backtrack and
144-- run the second parser if the first one fails.
161-- run the second parser if the first one fails.
145--
162--