@@ -45,6 +45,7 @@ import Language.Haskell.Exts.Extension -- (Extension, impliesExts, haskell2010)
4545import Data.List (intercalate )
4646import Control.Applicative
4747import Control.Monad (when , liftM , ap )
48+ import qualified Control.Monad.Fail as Fail
4849import Data.Monoid hiding ((<>) )
4950import Data.Semigroup (Semigroup (.. ))
5051-- To avoid import warnings for Control.Applicative, Data.Monoid, and Data.Semigroup
@@ -95,9 +96,11 @@ instance Applicative ParseResult where
9596
9697instance Monad ParseResult where
9798 return = ParseOk
98- fail = ParseFailed noLoc
99+ fail = Fail. fail
99100 ParseOk x >>= f = f x
100101 ParseFailed loc msg >>= _ = ParseFailed loc msg
102+ instance Fail. MonadFail ParseResult where
103+ fail = ParseFailed noLoc
101104
102105instance Semigroup m => Semigroup (ParseResult m ) where
103106 ParseOk x <> ParseOk y = ParseOk $ x <> y
@@ -243,6 +246,9 @@ instance Monad P where
243246 case m i x y l ch s mode of
244247 Failed loc msg -> Failed loc msg
245248 Ok s' a -> runP (k a) i x y l ch s' mode
249+ fail = Fail. fail
250+
251+ instance Fail. MonadFail P where
246252 fail s = P $ \ _r _col _line loc _ _stk _m -> Failed loc s
247253
248254atSrcLoc :: P a -> SrcLoc -> P a
@@ -348,6 +354,9 @@ instance Monad (Lex r) where
348354 return a = Lex $ \ k -> k a
349355 Lex v >>= f = Lex $ \ k -> v (\ a -> runL (f a) k)
350356 Lex v >> Lex w = Lex $ \ k -> v (\ _ -> w k)
357+ fail = Fail. fail
358+
359+ instance Fail. MonadFail (Lex r ) where
351360 fail s = Lex $ \ _ -> fail s
352361
353362-- Operations on this monad
0 commit comments