on master help sign in
Remove MonadCatch constraint in binary decode module
commitea224a4c4a78f984c1481e16cffaedbdd1fb70b0 authorHarendra Kumar <harendra@composewell.com> dateSat 20 Aug 2022, 18:49 (4 years ago) parent3ef32ce
1 file changed+24−25
src/Streamly/Internal/Data/Binary/Decode.hs+24−25
src/Streamly/Internal/Data/Binary/Decode.hs+24−25
@@ -24,7 +24,6 @@ module Streamly.Internal.Data.Binary.Decode
2424 )
2525where
2626
27−import Control.Monad.Catch (MonadCatch, throwM)
2827import Control.Monad.IO.Class (MonadIO)
2928import Data.Bits ((.|.), unsafeShiftL)
3029import Data.Word (Word8, Word16, Word32, Word64)
@@ -45,7 +44,7 @@ import qualified Streamly.Internal.Data.Parser.ParserD as PRD
4544-- /Pre-release/
4645--
4746{-# INLINE unit #-}
48−unit :: MonadCatch m => Parser m Word8 ()
47+unit :: Monad m => Parser m Word8 ()
4948unit = eqWord8 0 *> PR.fromPure ()
5049
5150{-# INLINE word8ToBool #-}
@@ -64,7 +63,7 @@ word8ToBool w = Left ("Invalid Bool encoding " ++ Prelude.show w)
6463-- /Pre-release/
6564--
6665{-# INLINE bool #-}
67−bool :: MonadCatch m => Parser m Word8 Bool
66+bool :: Monad m => Parser m Word8 Bool
6867bool = PR.either word8ToBool
6968
7069{-# INLINE word8ToOrdering #-}
@@ -85,7 +84,7 @@ word8ToOrdering w = Left ("Invalid Ordering encoding " ++ Prelude.show w)
8584-- /Pre-release/
8685--
8786{-# INLINE ordering #-}
88−ordering :: MonadCatch m => Parser m Word8 Ordering
87+ordering :: Monad m => Parser m Word8 Ordering
8988ordering = PR.either word8ToOrdering
9089
9190-- XXX should go in a Word8 parser module?
@@ -94,7 +93,7 @@ ordering = PR.either word8ToOrdering
9493-- /Pre-release/
9594--
9695{-# INLINE eqWord8 #-}
97−eqWord8 :: MonadCatch m => Word8 -> Parser m Word8 Word8
96+eqWord8 :: Monad m => Word8 -> Parser m Word8 Word8
9897eqWord8 b = PR.satisfy (== b)
9998
10099-- | Accept any byte.
@@ -102,12 +101,12 @@ eqWord8 b = PR.satisfy (== b)
102101-- /Pre-release/
103102--
104103{-# INLINE word8 #-}
105−word8 :: MonadCatch m => Parser m Word8 Word8
104+word8 :: Monad m => Parser m Word8 Word8
106105word8 = PR.satisfy (const True)
107106
108107-- | Big endian (MSB first) Word16
109108{-# INLINE word16beD #-}
110−word16beD :: MonadCatch m => PRD.Parser m Word8 Word16
109+word16beD :: Monad m => PRD.Parser m Word8 Word16
111110word16beD = PRD.Parser step initial extract
112111
113112 where
@@ -121,7 +120,7 @@ word16beD = PRD.Parser step initial extract
121120 step (Just' w) a =
122121 return $ PRD.Done 0 (w .|. fromIntegral a)
123122
124− extract _ = throwM $ PRD.ParseError "word16be: end of input"
123+ extract _ = return $ PRD.Error "word16be: end of input"
125124
126125-- | Parse two bytes as a 'Word16', the first byte is the MSB of the Word16 and
127126-- second byte is the LSB (big endian representation).
@@ -129,12 +128,12 @@ word16beD = PRD.Parser step initial extract
129128-- /Pre-release/
130129--
131130{-# INLINE word16be #-}
132−word16be :: MonadCatch m => Parser m Word8 Word16
131+word16be :: Monad m => Parser m Word8 Word16
133132word16be = PRD.toParserK word16beD
134133
135134-- | Little endian (LSB first) Word16
136135{-# INLINE word16leD #-}
137−word16leD :: MonadCatch m => PRD.Parser m Word8 Word16
136+word16leD :: Monad m => PRD.Parser m Word8 Word16
138137word16leD = PRD.Parser step initial extract
139138
140139 where
@@ -146,7 +145,7 @@ word16leD = PRD.Parser step initial extract
146145 step (Just' w) a =
147146 return $ PRD.Done 0 (w .|. fromIntegral a `unsafeShiftL` 8)
148147
149− extract _ = throwM $ PRD.ParseError "word16le: end of input"
148+ extract _ = return $ PRD.Error "word16le: end of input"
150149
151150-- | Parse two bytes as a 'Word16', the first byte is the LSB of the Word16 and
152151-- second byte is the MSB (little endian representation).
@@ -154,12 +153,12 @@ word16leD = PRD.Parser step initial extract
154153-- /Pre-release/
155154--
156155{-# INLINE word16le #-}
157−word16le :: MonadCatch m => Parser m Word8 Word16
156+word16le :: Monad m => Parser m Word8 Word16
158157word16le = PRD.toParserK word16leD
159158
160159-- | Big endian (MSB first) Word32
161160{-# INLINE word32beD #-}
162−word32beD :: MonadCatch m => PRD.Parser m Word8 Word32
161+word32beD :: Monad m => PRD.Parser m Word8 Word32
163162word32beD = PRD.Parser step initial extract
164163
165164 where
@@ -173,7 +172,7 @@ word32beD = PRD.Parser step initial extract
173172 in PRD.Continue 0 (Tuple' w1 (sh - 8))
174173 else PRD.Done 0 (w .|. fromIntegral a)
175174
176− extract _ = throwM $ PRD.ParseError "word32beD: end of input"
175+ extract _ = return $ PRD.Error "word32beD: end of input"
177176
178177-- | Parse four bytes as a 'Word32', the first byte is the MSB of the Word32
179178-- and last byte is the LSB (big endian representation).
@@ -181,12 +180,12 @@ word32beD = PRD.Parser step initial extract
181180-- /Pre-release/
182181--
183182{-# INLINE word32be #-}
184−word32be :: MonadCatch m => Parser m Word8 Word32
183+word32be :: Monad m => Parser m Word8 Word32
185184word32be = PRD.toParserK word32beD
186185
187186-- | Little endian (LSB first) Word32
188187{-# INLINE word32leD #-}
189−word32leD :: MonadCatch m => PRD.Parser m Word8 Word32
188+word32leD :: Monad m => PRD.Parser m Word8 Word32
190189word32leD = PRD.Parser step initial extract
191190
192191 where
@@ -199,7 +198,7 @@ word32leD = PRD.Parser step initial extract
199198 then PRD.Continue 0 (Tuple' w1 (sh + 8))
200199 else PRD.Done 0 w1
201200
202− extract _ = throwM $ PRD.ParseError "word32leD: end of input"
201+ extract _ = return $ PRD.Error "word32leD: end of input"
203202
204203-- | Parse four bytes as a 'Word32', the first byte is the MSB of the Word32
205204-- and last byte is the LSB (big endian representation).
@@ -207,12 +206,12 @@ word32leD = PRD.Parser step initial extract
207206-- /Pre-release/
208207--
209208{-# INLINE word32le #-}
210−word32le :: MonadCatch m => Parser m Word8 Word32
209+word32le :: Monad m => Parser m Word8 Word32
211210word32le = PRD.toParserK word32leD
212211
213212-- | Big endian (MSB first) Word64
214213{-# INLINE word64beD #-}
215−word64beD :: MonadCatch m => PRD.Parser m Word8 Word64
214+word64beD :: Monad m => PRD.Parser m Word8 Word64
216215word64beD = PRD.Parser step initial extract
217216
218217 where
@@ -226,7 +225,7 @@ word64beD = PRD.Parser step initial extract
226225 in PRD.Continue 0 (Tuple' w1 (sh - 8))
227226 else PRD.Done 0 (w .|. fromIntegral a)
228227
229− extract _ = throwM $ PRD.ParseError "word64beD: end of input"
228+ extract _ = return $ PRD.Error "word64beD: end of input"
230229
231230-- | Parse eight bytes as a 'Word64', the first byte is the MSB of the Word64
232231-- and last byte is the LSB (big endian representation).
@@ -234,12 +233,12 @@ word64beD = PRD.Parser step initial extract
234233-- /Pre-release/
235234--
236235{-# INLINE word64be #-}
237−word64be :: MonadCatch m => Parser m Word8 Word64
236+word64be :: Monad m => Parser m Word8 Word64
238237word64be = PRD.toParserK word64beD
239238
240239-- | Little endian (LSB first) Word64
241240{-# INLINE word64leD #-}
242−word64leD :: MonadCatch m => PRD.Parser m Word8 Word64
241+word64leD :: Monad m => PRD.Parser m Word8 Word64
243242word64leD = PRD.Parser step initial extract
244243
245244 where
@@ -252,7 +251,7 @@ word64leD = PRD.Parser step initial extract
252251 then PRD.Continue 0 (Tuple' w1 (sh + 8))
253252 else PRD.Done 0 w1
254253
255− extract _ = throwM $ PRD.ParseError "word64leD: end of input"
254+ extract _ = return $ PRD.Error "word64leD: end of input"
256255
257256-- | Parse eight bytes as a 'Word64', the first byte is the MSB of the Word64
258257-- and last byte is the LSB (big endian representation).
@@ -260,7 +259,7 @@ word64leD = PRD.Parser step initial extract
260259-- /Pre-release/
261260--
262261{-# INLINE word64le #-}
263−word64le :: MonadCatch m => Parser m Word8 Word64
262+word64le :: Monad m => Parser m Word8 Word64
264263word64le = PRD.toParserK word64leD
265264
266265-------------------------------------------------------------------------------
@@ -272,6 +271,6 @@ word64le = PRD.toParserK word64leD
272271-- /Pre-release/
273272--
274273{-# INLINE word64host #-}
275−word64host :: (MonadIO m, MonadCatch m) => Parser m Word8 Word64
274+word64host :: MonadIO m => Parser m Word8 Word64
276275word64host =
277276 fmap (A.unsafeIndex 0 . A.castUnsafe) $ PR.takeEQ 8 (A.writeN 8)