@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns, CPP, GeneralizedNewtypeDeriving, OverloadedStrings,
1+{-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving, OverloadedStrings,
22 Rank2Types, RecordWildCards, TypeFamilies #-}
33-- |
44-- Module : Data.Attoparsec.Internal.Types
@@ -25,13 +25,13 @@ module Data.Attoparsec.Internal.Types
2525 , Chunk(..)
2626 ) where
2727
28−#if !MIN_VERSION_base(4,8,0)
29−import Control.Applicative (Applicative(..), (<$>))
30−import Data.Monoid (Monoid(..))
31−#endif
28+import Control.Applicative as App (Applicative(..), (<$>))
3229import Control.Applicative (Alternative(..))
3330import Control.DeepSeq (NFData(rnf))
3431import Control.Monad (MonadPlus(..))
32+import qualified Control.Monad.Fail as Fail (MonadFail(..))
33+import Data.Monoid as Mon (Monoid(..))
34+import Data.Semigroup (Semigroup(..))
3535import Data.Word (Word8)
3636import Data.ByteString (ByteString)
3737import qualified Data.ByteString as BS
@@ -127,17 +127,19 @@ type Success i t a r = t -> Pos -> More -> a -> IResult i r
127127data More = Complete | Incomplete
128128 deriving (Eq, Show)
129129
130−instance Monoid More where
131− mappend c@Complete _ = c
132− mappend _ m = m
133− mempty = Incomplete
130+instance Semigroup More where
131+ c@Complete <> _ = c
132+ _ <> m = m
133+
134+instance Mon.Monoid More where
135+ mappend = (<>)
136+ mempty = Incomplete
134137
135138instance Monad (Parser i) where
136− fail err = Parser $ \t pos more lose _succ -> lose t pos more [] msg
137− where msg = "Failed reading: " ++ err
139+ fail = Fail.fail
138140 {-# INLINE fail #-}
139141
140− return v = Parser $ \t pos more _lose succ -> succ t pos more v
142+ return = App.pure
141143 {-# INLINE return #-}
142144
143145 m >>= k = Parser $ \t !pos more lose succ ->
@@ -145,6 +147,15 @@ instance Monad (Parser i) where
145147 in runParser m t pos more lose succ'
146148 {-# INLINE (>>=) #-}
147149
150+ (>>) = (*>)
151+ {-# INLINE (>>) #-}
152+
153+
154+instance Fail.MonadFail (Parser i) where
155+ fail err = Parser $ \t pos more lose _succ -> lose t pos more [] msg
156+ where msg = "Failed reading: " ++ err
157+ {-# INLINE fail #-}
158+
148159plus :: Parser i a -> Parser i a -> Parser i a
149160plus f g = Parser $ \t pos more lose succ ->
150161 let lose' t' _pos' more' _ctx _msg = runParser g t' pos more' lose succ
@@ -169,23 +180,23 @@ apP d e = do
169180{-# INLINE apP #-}
170181
171182instance Applicative (Parser i) where
172− pure = return
183+ pure v = Parser $ \t pos more _lose succ -> succ t pos more v
173184 {-# INLINE pure #-}
174185 (<*>) = apP
175186 {-# INLINE (<*>) #-}
176−
177− -- These definitions are equal to the defaults, but this
178− -- way the optimizer doesn't have to work so hard to figure
179− -- that out.
180− (*>) = (>>)
187+ m *> k = m >>= \_ -> k
181188 {-# INLINE (*>) #-}
182− x <* y = x >>= \a -> y >> return a
189+ x <* y = x >>= \a -> y >> pure a
183190 {-# INLINE (<*) #-}
184191
192+instance Semigroup (Parser i a) where
193+ (<>) = plus
194+ {-# INLINE (<>) #-}
195+
185196instance Monoid (Parser i a) where
186197 mempty = fail "mempty"
187198 {-# INLINE mempty #-}
188− mappend = plus
199+ mappend = (<>)
189200 {-# INLINE mappend #-}
190201
191202instance Alternative (Parser i) where
@@ -197,7 +208,7 @@ instance Alternative (Parser i) where
197208
198209 many v = many_v
199210 where many_v = some_v <|> pure []
200− some_v = (:) <$> v <*> many_v
211+ some_v = (:) App.<$> v <*> many_v
201212 {-# INLINE many #-}
202213
203214 some v = some_v
@@ -206,10 +217,6 @@ instance Alternative (Parser i) where
206217 some_v = (:) <$> v <*> many_v
207218 {-# INLINE some #-}
208219
209−(<>) :: (Monoid m) => m -> m -> m
210−(<>) = mappend
211−{-# INLINE (<>) #-}
212−
213220-- | A common interface for input chunks.
214221class Monoid c => Chunk c where
215222 type ChunkElem c