Commits

Bryan O'Sullivan committed ebadc61

Add a MonadFix instance.

Comments (0)

Files changed (1)

src/Text/ParserCombinators/ByteStringParser.hs

 
 import Control.Applicative (Alternative(..), Applicative(..), (<$>), (<*), (*>))
 import Control.Monad (MonadPlus(..), ap, liftM2)
+import Control.Monad.Fix (MonadFix(..))
 import qualified Data.ByteString.Char8 as SB
 import qualified Data.ByteString.Lazy.Char8 as LB
 import qualified Data.ByteString.Lazy.Internal as LB
                 Left (s', msgs) -> Left (s', msgs)
     fail err = Parser $ \(S sb lb _) -> Left (sb +: lb, [err])
 
+instance MonadFix Parser where
+    mfix f = Parser $ \s ->
+             let r = case r of
+                       Right (a, _) -> unParser (f a) s
+                       err -> err
+             in r
+
 zero :: Parser a
 zero = Parser $ \(S sb lb _) -> Left (sb +: lb, [])
 {-# INLINE zero #-}