on master help sign in
Remove MonadCatch constraints from parser benchmarks
b870dbeHarendra Kumar
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+17−17
@@ -15,7 +15,7 @@ module Main
15 ) where
15 ) where
16
16
17import Control.DeepSeq (NFData(..))
17import Control.DeepSeq (NFData(..))
18−import Control.Monad.Catch (MonadCatch, MonadThrow)
18+import Control.Monad.Catch (MonadThrow)
19import Data.Foldable (asum)
19import Data.Foldable (asum)
20import Data.Function ((&))
20import Data.Function ((&))
21import Data.Functor (($>))
21import Data.Functor (($>))
@@ -71,7 +71,7 @@ drainWhile :: MonadThrow m => (a -> Bool) -> PR.Parser m a ()
71drainWhile p = PR.takeWhile p Fold.drain
71drainWhile p = PR.takeWhile p Fold.drain
72
72
73{-# INLINE takeStartBy #-}
73{-# INLINE takeStartBy #-}
74−takeStartBy :: MonadCatch m => Int -> Stream m Int -> m ()
74+takeStartBy :: MonadThrow m => Int -> Stream m Int -> m ()
75takeStartBy value stream = do
75takeStartBy value stream = do
76 stream1 <- return . fromMaybe (Stream.fromPure (value + 1)) =<< IsStream.tail stream
76 stream1 <- return . fromMaybe (Stream.fromPure (value + 1)) =<< IsStream.tail stream
77 let stream2 = value `Stream.cons` stream1
77 let stream2 = value `Stream.cons` stream1
@@ -86,7 +86,7 @@ takeP :: MonadThrow m => Int -> Stream m a -> m ()
86takeP value = Stream.parseD (PR.takeP value (PR.fromFold Fold.drain))
86takeP value = Stream.parseD (PR.takeP value (PR.fromFold Fold.drain))
87
87
88{-# INLINE takeBetween #-}
88{-# INLINE takeBetween #-}
89−takeBetween :: MonadCatch m => Int -> Stream m a -> m ()
89+takeBetween :: MonadThrow m => Int -> Stream m a -> m ()
90takeBetween value = Stream.parseD (PR.takeBetween 0 value Fold.drain)
90takeBetween value = Stream.parseD (PR.takeBetween 0 value Fold.drain)
91
91
92{-# INLINE groupBy #-}
92{-# INLINE groupBy #-}
@@ -102,36 +102,36 @@ wordBy :: MonadThrow m => Int -> Stream m Int -> m ()
102wordBy value = Stream.parseD (PR.wordBy (>= value) Fold.drain)
102wordBy value = Stream.parseD (PR.wordBy (>= value) Fold.drain)
103
103
104{-# INLINE manyWordByEven #-}
104{-# INLINE manyWordByEven #-}
105−manyWordByEven :: MonadCatch m => Stream m Int -> m ()
105+manyWordByEven :: MonadThrow m => Stream m Int -> m ()
106manyWordByEven =
106manyWordByEven =
107 Stream.parseD (PR.many (PR.wordBy (Prelude.even) Fold.drain) Fold.drain)
107 Stream.parseD (PR.many (PR.wordBy (Prelude.even) Fold.drain) Fold.drain)
108
108
109{-# INLINE many #-}
109{-# INLINE many #-}
110−many :: MonadCatch m => Stream m Int -> m Int
110+many :: MonadThrow m => Stream m Int -> m Int
111many = Stream.parseD (PR.many (PR.satisfy (> 0)) Fold.length)
111many = Stream.parseD (PR.many (PR.satisfy (> 0)) Fold.length)
112
112
113{-# INLINE manyAlt #-}
113{-# INLINE manyAlt #-}
114−manyAlt :: MonadCatch m => Stream m Int -> m Int
114+manyAlt :: MonadThrow m => Stream m Int -> m Int
115manyAlt xs = do
115manyAlt xs = do
116 x <- Stream.parseD (AP.many (PR.satisfy (> 0))) xs
116 x <- Stream.parseD (AP.many (PR.satisfy (> 0))) xs
117 return $ Prelude.length x
117 return $ Prelude.length x
118
118
119{-# INLINE some #-}
119{-# INLINE some #-}
120−some :: MonadCatch m => Stream m Int -> m Int
120+some :: MonadThrow m => Stream m Int -> m Int
121some = Stream.parseD (PR.some (PR.satisfy (> 0)) Fold.length)
121some = Stream.parseD (PR.some (PR.satisfy (> 0)) Fold.length)
122
122
123{-# INLINE someAlt #-}
123{-# INLINE someAlt #-}
124−someAlt :: MonadCatch m => Stream m Int -> m Int
124+someAlt :: MonadThrow m => Stream m Int -> m Int
125someAlt xs = do
125someAlt xs = do
126 x <- Stream.parseD (AP.some (PR.satisfy (> 0))) xs
126 x <- Stream.parseD (AP.some (PR.satisfy (> 0))) xs
127 return $ Prelude.length x
127 return $ Prelude.length x
128
128
129{-#INLINE takeEndBy_ #-}
129{-#INLINE takeEndBy_ #-}
130−takeEndBy_ :: MonadCatch m => Int -> Stream m Int -> m ()
130+takeEndBy_ :: MonadThrow m => Int -> Stream m Int -> m ()
131takeEndBy_ value = Stream.parseD (PR.takeEndBy_ (>= value) (PR.fromFold Fold.drain))
131takeEndBy_ value = Stream.parseD (PR.takeEndBy_ (>= value) (PR.fromFold Fold.drain))
132
132
133{-# INLINE manyTill #-}
133{-# INLINE manyTill #-}
134−manyTill :: MonadCatch m => Int -> Stream m Int -> m Int
134+manyTill :: MonadThrow m => Int -> Stream m Int -> m Int
135manyTill value =
135manyTill value =
136 let p = PR.satisfy (> 0)
136 let p = PR.satisfy (> 0)
137 pcond = PR.satisfy (== value)
137 pcond = PR.satisfy (== value)
@@ -179,7 +179,7 @@ shortestAllAny value =
179 )
179 )
180
180
181{-# INLINE longestAllAny #-}
181{-# INLINE longestAllAny #-}
182−longestAllAny :: MonadCatch m
182+longestAllAny :: MonadThrow m
183 => Int -> Stream m Int -> m ()
183 => Int -> Stream m Int -> m ()
184longestAllAny value =
184longestAllAny value =
185 Stream.parseD
185 Stream.parseD
@@ -190,7 +190,7 @@ longestAllAny value =
190-}
190-}
191
191
192{-# INLINE sequenceParser #-}
192{-# INLINE sequenceParser #-}
193−sequenceParser :: MonadCatch m => Stream m Int -> m ()
193+sequenceParser :: MonadThrow m => Stream m Int -> m ()
194sequenceParser = Stream.parseD (PR.sequence Fold.drain (D.repeat (PR.satisfy $ const True)))
194sequenceParser = Stream.parseD (PR.sequence Fold.drain (D.repeat (PR.satisfy $ const True)))
195
195
196-------------------------------------------------------------------------------
196-------------------------------------------------------------------------------
@@ -229,7 +229,7 @@ parseManyGroupsRolling b =
229 Stream.fold Fold.drain . Stream.parseManyD (PR.groupByRolling (\_ _ -> b) Fold.drain)
229 Stream.fold Fold.drain . Stream.parseManyD (PR.groupByRolling (\_ _ -> b) Fold.drain)
230
230
231{-# INLINE parseManyGroupsRollingEither #-}
231{-# INLINE parseManyGroupsRollingEither #-}
232−parseManyGroupsRollingEither :: (MonadThrow m, MonadCatch m) =>
232+parseManyGroupsRollingEither :: MonadThrow m =>
233 (Int -> Int -> Bool) -> Int -> m ()
233 (Int -> Int -> Bool) -> Int -> m ()
234parseManyGroupsRollingEither cmp value = do
234parseManyGroupsRollingEither cmp value = do
235 sourceUnfoldrM value 1
235 sourceUnfoldrM value 1
@@ -237,7 +237,7 @@ parseManyGroupsRollingEither cmp value = do
237 & Stream.fold Fold.drain
237 & Stream.fold Fold.drain
238
238
239{-# INLINE parseManyGroupsRollingEitherAlt #-}
239{-# INLINE parseManyGroupsRollingEitherAlt #-}
240−parseManyGroupsRollingEitherAlt :: (MonadThrow m, MonadCatch m) =>
240+parseManyGroupsRollingEitherAlt :: MonadThrow m =>
241 (Int -> Int -> Bool) -> Int -> m ()
241 (Int -> Int -> Bool) -> Int -> m ()
242parseManyGroupsRollingEitherAlt cmp value = do
242parseManyGroupsRollingEitherAlt cmp value = do
243 sourceUnfoldrM value 1
243 sourceUnfoldrM value 1
@@ -296,7 +296,7 @@ sequence value xs = do
296 return $ length x
296 return $ length x
297
297
298{-# INLINE sequence_ #-}
298{-# INLINE sequence_ #-}
299−sequence_ :: MonadCatch m => Int -> Stream m Int -> m ()
299+sequence_ :: MonadThrow m => Int -> Stream m Int -> m ()
300sequence_ value xs =
300sequence_ value xs =
301 Stream.parseD (foldr f (return ()) (replicate value (PR.takeBetween 0 1 Fold.drain))) xs
301 Stream.parseD (foldr f (return ()) (replicate value (PR.takeBetween 0 1 Fold.drain))) xs
302
302
@@ -309,14 +309,14 @@ sequence_ value xs =
309-- quadratic performance complexity.
309-- quadratic performance complexity.
310--
310--
311{-# INLINE choiceAsum #-}
311{-# INLINE choiceAsum #-}
312−choiceAsum :: MonadCatch m => Int -> Stream m Int -> m Int
312+choiceAsum :: MonadThrow m => Int -> Stream m Int -> m Int
313choiceAsum value =
313choiceAsum value =
314 Stream.parseD (asum (replicate value (PR.satisfy (< 0)))
314 Stream.parseD (asum (replicate value (PR.satisfy (< 0)))
315 AP.<|> PR.satisfy (> 0))
315 AP.<|> PR.satisfy (> 0))
316
316
317{-
317{-
318{-# INLINE choice #-}
318{-# INLINE choice #-}
319−choice :: MonadCatch m => Int -> Stream m Int -> m Int
319+choice :: MonadThrow m => Int -> Stream m Int -> m Int
320choice value =
320choice value =
321 Stream.parseD
321 Stream.parseD
322 (PR.choice (replicate value (PR.satisfy (< 0))) AP.<|> PR.satisfy (> 0))
322 (PR.choice (replicate value (PR.satisfy (< 0))) AP.<|> PR.satisfy (> 0))