Commits

Bryan O'Sullivan committed ef59562

IResult does not need to be parameterised on internal state

Comments (0)

Files changed (5)

Data/Attoparsec/ByteString/Internal.hs

 import qualified Data.ByteString.Unsafe as B
 
 type Parser = T.Parser B.ByteString Buffer
-type Result = IResult B.ByteString Buffer
+type Result = IResult B.ByteString
 type Failure r = T.Failure B.ByteString Buffer r
 type Success a r = T.Success B.ByteString Buffer a r
 
 -- | Ask for input.  If we receive any, pass it to a success
 -- continuation, otherwise to a failure continuation.
 prompt :: Buffer -> Pos -> More
-       -> (Buffer -> Pos -> More -> IResult ByteString Buffer r)
-       -> (Buffer -> Pos -> More -> IResult ByteString Buffer r)
-       -> IResult ByteString Buffer r
+       -> (Buffer -> Pos -> More -> IResult ByteString r)
+       -> (Buffer -> Pos -> More -> IResult ByteString r)
+       -> IResult ByteString r
 prompt t pos _more lose succ = Partial $ \s ->
   if B.null s
   then lose t pos Complete

Data/Attoparsec/Combinator.hs

 
 -- | If a parser has returned a 'T.Partial' result, supply it with more
 -- input.
-feed :: Monoid i => IResult i t r -> i -> IResult i t r
+feed :: Monoid i => IResult i r -> i -> IResult i r
 feed f@(Fail _ _ _) _ = f
 feed (Partial k) d    = k d
 feed (Done t r) d     = Done (mappend t d) r

Data/Attoparsec/Internal.hs

 -- If both 'IResult's are 'Partial', the result will be 'Nothing', as
 -- they are incomplete and hence their equality cannot be known.
 -- (This is why there is no 'Eq' instance for 'IResult'.)
-compareResults :: (Eq i, Eq r) => IResult i t r -> IResult i t r -> Maybe Bool
+compareResults :: (Eq i, Eq r) => IResult i r -> IResult i r -> Maybe Bool
 compareResults (Fail t0 ctxs0 msg0) (Fail t1 ctxs1 msg1) =
     Just (t0 == t1 && ctxs0 == ctxs1 && msg0 == msg1)
 compareResults (Done t0 r0) (Done t1 r1) =

Data/Attoparsec/Internal/Types.hs

 --
 -- This type is an instance of 'Functor', where 'fmap' transforms the
 -- value in a 'Done' result.
-data IResult i t r =
+data IResult i r =
     Fail i [String] String
     -- ^ The parse failed.  The @i@ parameter is the input that had
     -- not yet been consumed when the failure occurred.  The
     -- @[@'String'@]@ is a list of contexts in which the error
     -- occurred.  The 'String' is the message describing the error, if
     -- any.
-  | Partial (i -> IResult i t r)
+  | Partial (i -> IResult i r)
     -- ^ Supply this continuation with more input so that the parser
     -- can resume.  To indicate that no more input is available, pass
     -- an empty string to the continuation.
     -- ^ The parse succeeded.  The @i@ parameter is the input that had
     -- not yet been consumed (if any) when the parse succeeded.
 
-instance (Show i, Show r) => Show (IResult i t r) where
+instance (Show i, Show r) => Show (IResult i r) where
     show (Fail t stk msg) =
       unwords [ "Fail", show t, show stk, show msg]
     show (Partial _)          = "Partial _"
     show (Done t r)       = unwords ["Done", show t, show r]
 
-instance (NFData i, NFData r) => NFData (IResult i t r) where
+instance (NFData i, NFData r) => NFData (IResult i r) where
     rnf (Fail t stk msg) = rnf t `seq` rnf stk `seq` rnf msg
     rnf (Partial _)  = ()
     rnf (Done t r)   = rnf t `seq` rnf r
     {-# INLINE rnf #-}
 
-instance Functor (IResult i t) where
+instance Functor (IResult i) where
     fmap _ (Fail t stk msg) = Fail t stk msg
     fmap f (Partial k)      = Partial (fmap f . k)
     fmap f (Done t r)   = Done t (f r)
       runParser :: forall r. t -> Pos -> More
                 -> Failure i t   r
                 -> Success i t a r
-                -> IResult i t r
+                -> IResult i r
     }
 
 type Failure i t   r = t -> Pos -> More -> [String] -> String
-                       -> IResult i t r
-type Success i t a r = t -> Pos -> More -> a -> IResult i t r
+                       -> IResult i r
+type Success i t a r = t -> Pos -> More -> a -> IResult i r
 
 -- | Have we read all available input?
 data More = Complete | Incomplete

Data/Attoparsec/Text/Internal.hs

 import qualified Data.Text.Unsafe as T
 
 type Parser = T.Parser Text Buffer
-type Result = IResult Text Buffer
+type Result = IResult Text
 type Failure r = T.Failure Text Buffer r
 type Success a r = T.Success Text Buffer a r
 
 -- | Ask for input.  If we receive any, pass it to a success
 -- continuation, otherwise to a failure continuation.
 prompt :: Buffer -> Pos -> More
-       -> (Buffer -> Pos -> More -> IResult Text Buffer r)
-       -> (Buffer -> Pos -> More -> IResult Text Buffer r)
-       -> IResult Text Buffer r
+       -> (Buffer -> Pos -> More -> IResult Text r)
+       -> (Buffer -> Pos -> More -> IResult Text r)
+       -> IResult Text r
 prompt t pos _more lose succ = Partial $ \s ->
   if T.null s
   then lose t pos Complete