Commits

Bryan O'Sullivan committed 87b295d

Drop some internal Monoid instances that add no value.

  • Participants
  • Parent commits e1b76aa

Comments (0)

Files changed (1)

Data/Attoparsec/Internal.hs

 data More = Complete | Incomplete
             deriving (Eq, Show)
 
-plusMore :: More -> More -> More
-plusMore Complete _ = Complete
-plusMore _ Complete = Complete
-plusMore _ _        = Incomplete
-{-# INLINE plusMore #-}
-
-instance Monoid More where
-    mempty  = Incomplete
-    mappend = plusMore
-
 data S = S {
       input  :: !B.ByteString
     , _added :: B.ByteString
     show (Done bs r) = "Done " ++ show bs ++ " " ++ show r
 
 addS :: S -> S -> S
-addS (S s0 a0 c0) (S _s1 a1 c1) = S (s0 +++ a1) (a0 +++ a1) (mappend c0 c1)
+addS (S s0 a0 c0) (S _s1 a1 c1) = S (s0 +++ a1) (a0 +++ a1) (c0 <> c1)
+  where
+    Complete <> _ = Complete
+    _ <> Complete = Complete
+    _ <> _        = Incomplete
 {-# INLINE addS #-}
 
-instance Monoid S where
-    mempty  = S B.empty B.empty Incomplete
-    mappend = addS
-
 bindP :: Parser a -> (a -> Parser b) -> Parser b
 bindP m g =
     Parser (\st0 kf ks -> runParser m st0 kf (\s a -> runParser (g a) s kf ks))
 
 plus :: Parser a -> Parser a -> Parser a
 plus a b = Parser $ \st0 kf ks ->
-           let kf' st1 _ _ = runParser b (mappend st0 st1) kf ks
+           let kf' st1 _ _ = runParser b (addS st0 st1) kf ks
                !st2 = noAdds st0
            in  runParser a st2 kf' ks
 {-# INLINE plus #-}
 -- retain input for longer than is desirable.
 try :: Parser a -> Parser a
 try p = Parser $ \st0 kf ks ->
-        runParser p (noAdds st0) (kf . mappend st0) ks
+        runParser p (noAdds st0) (kf . addS st0) ks
 
 -- | The parser @satisfy p@ succeeds for any byte for which the
 -- predicate @p@ returns 'True'. Returns the byte that is actually
              if B.null input
              then if more == Complete
                   then ks st0 ()
-                  else let kf' st1 _ _ = ks (mappend st0 st1) ()
-                           ks' st1 _   = kf (mappend st0 st1) [] "endOfInput"
+                  else let kf' st1 _ _ = ks (addS st0 st1) ()
+                           ks' st1 _   = kf (addS st0 st1) [] "endOfInput"
                        in  runParser demandInput st0 kf' ks'
              else kf st0 [] "endOfInput"