on master help sign in
Clean up hlint warnings
1100c23Sanchayan Maity
.hlint.ignore−11
@@ -1,5 +1,3 @@
1−src/Streamly/Internal/BaseCompat.hs
2−src/Streamly/Internal/Control/Monad.hs
3src/Streamly/Internal/Data/Stream/SVar.hs
1src/Streamly/Internal/Data/Stream/SVar.hs
4src/Streamly/Internal/Data/Stream/Serial.hs
2src/Streamly/Internal/Data/Stream/Serial.hs
5src/Streamly/Internal/Data/Stream/Zip.hs
3src/Streamly/Internal/Data/Stream/Zip.hs
@@ -14,16 +12,7 @@ src/Streamly/Internal/Data/Stream/StreamD/Type.hs
14src/Streamly/Internal/Data/Stream/StreamDK/Type.hs
12src/Streamly/Internal/Data/Stream/StreamDK/Type.hs
15src/Streamly/Internal/Data/Stream/StreamD.hs
13src/Streamly/Internal/Data/Stream/StreamD.hs
16src/Streamly/Internal/Data/Pipe/Types.hs
14src/Streamly/Internal/Data/Pipe/Types.hs
17−src/Streamly/Internal/Data/Sink.hs
18−src/Streamly/Internal/Data/Parser/ParserD/Types.hs
19−src/Streamly/Internal/Data/Parser/ParserD.hs
20src/Streamly/Internal/Data/Prim/Array/Types.hs
15src/Streamly/Internal/Data/Prim/Array/Types.hs
21src/Streamly/Internal/Data/SmallArray/Types.hs
16src/Streamly/Internal/Data/SmallArray/Types.hs
22−src/Streamly/Internal/Data/Unfold.hs
23src/Streamly/Internal/Data/Unicode/Stream.hs
17src/Streamly/Internal/Data/Unicode/Stream.hs
24−src/Streamly/Internal/Memory/Array/Types.hs
25src/Streamly/Internal/Mutable/Prim/Var.hs
18src/Streamly/Internal/Mutable/Prim/Var.hs
26−src/Streamly/Internal/Network/Socket.hs
27−src/Streamly/Internal/Data/Stream/Prelude.hs
28−src/Streamly/FileSystem/FDIO.hs
29−src/Streamly/Data/Unfold.hs
.hlint.yaml+3
@@ -18,6 +18,9 @@
18- ignore: {name: "Use <>"}
18- ignore: {name: "Use <>"}
19- ignore: {name: "Use fewer imports"}
19- ignore: {name: "Use fewer imports"}
20- ignore: {name: "Use camelCase"}
20- ignore: {name: "Use camelCase"}
21+- ignore: {name: "Use <$>"}
22+- ignore: {name: "Use uncurry"}
23+- ignore: {name: "Redundant $!"}
21
24
22
25
23# Specify additional command line arguments
26# Specify additional command line arguments
src/Streamly/FileSystem/FDIO.hs+3−4
@@ -22,9 +22,9 @@ module Streamly.FileSystem.FDIO
22 )
22 )
23where
23where
24
24
25+import Control.Monad (when)
25#if !defined(mingw32_HOST_OS)
26#if !defined(mingw32_HOST_OS)
26import Control.Concurrent (threadWaitWrite)
27import Control.Concurrent (threadWaitWrite)
27−import Control.Monad (when)
28import Data.Int (Int64)
28import Data.Int (Int64)
29import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
29import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
30#if __GLASGOW_HASKELL__ >= 802
30#if __GLASGOW_HASKELL__ >= 802
@@ -193,9 +193,8 @@ writeAll :: FD -> Ptr Word8 -> Int -> IO ()
193writeAll fd ptr bytes = do
193writeAll fd ptr bytes = do
194 res <- write fd ptr 0 (fromIntegral bytes)
194 res <- write fd ptr 0 (fromIntegral bytes)
195 let res' = fromIntegral res
195 let res' = fromIntegral res
196− if res' < bytes
196+ when (res' < bytes) $
197− then writeAll fd (ptr `plusPtr` res') (bytes - res')
197+ writeAll fd (ptr `plusPtr` res') (bytes - res')
198− else return ()
199
198
200-------------------------------------------------------------------------------
199-------------------------------------------------------------------------------
201-- Vector IO
200-- Vector IO
src/Streamly/Internal/BaseCompat.hs+2−2
@@ -22,6 +22,6 @@ import Data.Coerce (Coercible, coerce)
22
22
23#if !(MIN_VERSION_base(4,9,0))
23#if !(MIN_VERSION_base(4,9,0))
24{-# NOINLINE errorWithoutStackTrace #-}
24{-# NOINLINE errorWithoutStackTrace #-}
25−errorWithoutStackTrace :: [Char] -> a
25+errorWithoutStackTrace :: String -> a
26−errorWithoutStackTrace s = error s
26+errorWithoutStackTrace = error
27#endif
27#endif
src/Streamly/Internal/Control/Monad.hs+1−1
@@ -23,4 +23,4 @@ import Control.Monad.Catch (MonadCatch, catch, SomeException)
23--
23--
24{-# INLINE discard #-}
24{-# INLINE discard #-}
25discard :: MonadCatch m => m b -> m ()
25discard :: MonadCatch m => m b -> m ()
26−discard action = (void $ action) `catch` (\(_ :: SomeException) -> return ())
26+discard action = void action `catch` (\(_ :: SomeException) -> return ())
src/Streamly/Internal/Data/Parser/ParserD.hs+2−14
@@ -235,13 +235,7 @@ any predicate = Parser step initial return
235
235
236 initial = return False
236 initial = return False
237
237
238− step s a = return $
239− if s
240− then Done 0 True
241− else
242− if predicate a
243− then Done 0 True
244− else Partial 0 False
238+ step s a = return (if s || predicate a then Done 0 True else Partial 0 False)
245
239
246{-# INLINABLE all #-}
240{-# INLINABLE all #-}
247all :: Monad m => (a -> Bool) -> Parser m a Bool
241all :: Monad m => (a -> Bool) -> Parser m a Bool
@@ -251,13 +245,7 @@ all predicate = Parser step initial return
251
245
252 initial = return True
246 initial = return True
253
247
254− step s a = return $
255− if s
256− then
257− if predicate a
258− then Partial 0 True
248+ step s a = return (if s && predicate a then Partial 0 True else Done 0 False)
259− else Done 0 False
260− else Done 0 False
261
249
262-------------------------------------------------------------------------------
250-------------------------------------------------------------------------------
263-- Failing Parsers
251-- Failing Parsers
src/Streamly/Internal/Data/Parser/ParserD/Types.hs+2−2
@@ -263,7 +263,7 @@ yield b = Parser (\_ _ -> pure $ Done 1 b) -- step
263yieldM :: Monad m => m b -> Parser m a b
263yieldM :: Monad m => m b -> Parser m a b
264yieldM b = Parser (\_ _ -> Done 1 <$> b) -- step
264yieldM b = Parser (\_ _ -> Done 1 <$> b) -- step
265 (pure ()) -- initial
265 (pure ()) -- initial
266− (\_ -> b) -- extract
266+ (const b) -- extract
267
267
268-------------------------------------------------------------------------------
268-------------------------------------------------------------------------------
269-- Sequential applicative
269-- Sequential applicative
@@ -353,7 +353,7 @@ split_ (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
353 Error err -> Error err) <$> stepL st a <*> initialR
353 Error err -> Error err) <$> stepL st a <*> initialR
354
354
355 step (SeqAR st) a = do
355 step (SeqAR st) a = do
356− (\r -> case r of
356+ (\case
357 Partial n s -> Partial n (SeqAR s)
357 Partial n s -> Partial n (SeqAR s)
358 Continue n s -> Continue n (SeqAR s)
358 Continue n s -> Continue n (SeqAR s)
359 Done n b -> Done n b
359 Done n b -> Done n b
src/Streamly/Internal/Data/Sink.hs+3−3
@@ -57,7 +57,7 @@ module Streamly.Internal.Data.Sink
57 )
57 )
58where
58where
59
59
60−import Control.Monad (when, void)
60+import Control.Monad ((>=>), when, void)
61import Data.Map.Strict (Map)
61import Data.Map.Strict (Map)
62import Prelude
62import Prelude
63 hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
63 hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
@@ -197,7 +197,7 @@ demux kv = Sink step
197{-# INLINE unzipM #-}
197{-# INLINE unzipM #-}
198unzipM :: Monad m => (a -> m (b,c)) -> Sink m b -> Sink m c -> Sink m a
198unzipM :: Monad m => (a -> m (b,c)) -> Sink m b -> Sink m c -> Sink m a
199unzipM f (Sink stepB) (Sink stepC) =
199unzipM f (Sink stepB) (Sink stepC) =
200− Sink (\a -> f a >>= \(b,c) -> stepB b >> stepC c)
200+ Sink (f >=> (\(b, c) -> stepB b >> stepC c))
201
201
202-- | Same as 'unzipM' but with a pure unzip function.
202-- | Same as 'unzipM' but with a pure unzip function.
203{-# INLINE unzip #-}
203{-# INLINE unzip #-}
@@ -216,7 +216,7 @@ lmap f (Sink step) = Sink (step . f)
216-- | Map a monadic function on the input of a 'Sink'.
216-- | Map a monadic function on the input of a 'Sink'.
217{-# INLINABLE lmapM #-}
217{-# INLINABLE lmapM #-}
218lmapM :: Monad m => (a -> m b) -> Sink m b -> Sink m a
218lmapM :: Monad m => (a -> m b) -> Sink m b -> Sink m a
219−lmapM f (Sink step) = Sink (\x -> f x >>= step)
219+lmapM f (Sink step) = Sink (f >=> step)
220
220
221-- | Filter the input of a 'Sink' using a pure predicate function.
221-- | Filter the input of a 'Sink' using a pure predicate function.
222{-# INLINABLE lfilter #-}
222{-# INLINABLE lfilter #-}
src/Streamly/Internal/Data/SmallArray/Types.hs+2−1
@@ -679,7 +679,8 @@ instance MonadPlus SmallArray where
679 mplus = (<|>)
679 mplus = (<|>)
680
680
681zipW :: String -> (a -> b -> c) -> SmallArray a -> SmallArray b -> SmallArray c
681zipW :: String -> (a -> b -> c) -> SmallArray a -> SmallArray b -> SmallArray c
682+zipW nm f sa sb =
682−zipW nm = \f sa sb -> let mn = length sa `min` length sb in
683+ let mn = length sa `min` length sb in
683 createSmallArray mn (die nm "impossible") $ \mc ->
684 createSmallArray mn (die nm "impossible") $ \mc ->
684 fix ? 0 $ \go i -> when (i < mn) $ do
685 fix ? 0 $ \go i -> when (i < mn) $ do
685 x <- indexSmallArrayM sa i
686 x <- indexSmallArrayM sa i
src/Streamly/Internal/Data/Stream/Prelude.hs+1−1
@@ -148,7 +148,7 @@ foldrMx step final project m = D.foldrMx step final project $ D.toStreamD m
148
148
149{-# INLINE foldr #-}
149{-# INLINE foldr #-}
150foldr :: (Monad m, IsStream t) => (a -> b -> b) -> b -> t m a -> m b
150foldr :: (Monad m, IsStream t) => (a -> b -> b) -> b -> t m a -> m b
151−foldr f z = foldrM (\a b -> b >>= return . f a) (return z)
151+foldr f z = foldrM (\a b -> f a <$> b) (return z)
152
152
153-- | Like 'foldlx'', but with a monadic step function.
153-- | Like 'foldlx'', but with a monadic step function.
154--
154--
src/Streamly/Internal/Data/Unfold.hs+18−18
@@ -126,6 +126,7 @@ module Streamly.Internal.Data.Unfold
126where
126where
127
127
128import Control.Exception (Exception, mask_)
128import Control.Exception (Exception, mask_)
129+import Control.Monad ((>=>))
129import Control.Monad.IO.Class (MonadIO(..))
130import Control.Monad.IO.Class (MonadIO(..))
130import Control.Monad.Trans.Control (MonadBaseControl, liftBaseOp_)
131import Control.Monad.Trans.Control (MonadBaseControl, liftBaseOp_)
131import Data.Void (Void)
132import Data.Void (Void)
@@ -173,7 +174,7 @@ lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
173-- /Internal/
174-- /Internal/
174{-# INLINE_NORMAL lmapM #-}
175{-# INLINE_NORMAL lmapM #-}
175lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
176lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
176−lmapM f (Unfold ustep uinject) = Unfold ustep (\x -> f x >>= uinject)
177+lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
177
178
178-- XXX change the signature to the following?
179-- XXX change the signature to the following?
179-- supply :: a -> Unfold m a b -> Unfold m Void b
180-- supply :: a -> Unfold m a b -> Unfold m Void b
@@ -289,7 +290,7 @@ mapM f (Unfold ustep uinject) = Unfold step uinject
289 case r of
290 case r of
290 Yield x s -> f x >>= \a -> return $ Yield a s
291 Yield x s -> f x >>= \a -> return $ Yield a s
291 Skip s -> return $ Skip s
292 Skip s -> return $ Skip s
292− Stop -> return $ Stop
293+ Stop -> return Stop
293
294
294{-# INLINE_NORMAL mapMWithInput #-}
295{-# INLINE_NORMAL mapMWithInput #-}
295mapMWithInput :: Monad m => (a -> b -> m c) -> Unfold m a b -> Unfold m a c
296mapMWithInput :: Monad m => (a -> b -> m c) -> Unfold m a b -> Unfold m a c
@@ -305,7 +306,7 @@ mapMWithInput f (Unfold ustep uinject) = Unfold step inject
305 case r of
306 case r of
306 Yield x s -> f inp x >>= \a -> return $ Yield a (inp, s)
307 Yield x s -> f inp x >>= \a -> return $ Yield a (inp, s)
307 Skip s -> return $ Skip (inp, s)
308 Skip s -> return $ Skip (inp, s)
308− Stop -> return $ Stop
309+ Stop -> return Stop
309
310
310-------------------------------------------------------------------------------
311-------------------------------------------------------------------------------
311-- Convert streams into unfolds
312-- Convert streams into unfolds
@@ -437,7 +438,7 @@ replicateM n = Unfold step inject
437 step (x, i) = return $
438 step (x, i) = return $
438 if i <= 0
439 if i <= 0
439 then Stop
440 then Stop
440− else Yield x (x, (i - 1))
441+ else Yield x (x, i - 1)
441
442
442-- | Generates an infinite stream repeating the seed.
443-- | Generates an infinite stream repeating the seed.
443--
444--
@@ -536,7 +537,7 @@ enumerateFromStepIntegral = Unfold step inject
536 where
537 where
537 inject (from, stride) = from `seq` stride `seq` return (from, stride)
538 inject (from, stride) = from `seq` stride `seq` return (from, stride)
538 {-# INLINE_LATE step #-}
539 {-# INLINE_LATE step #-}
539− step !(x, stride) = return $ Yield x $! (x + stride, stride)
540+ step (x, stride) = return $ Yield x $! (x + stride, stride)
540
541
541-- We are assuming that "to" is constrained by the type to be within
542-- We are assuming that "to" is constrained by the type to be within
542-- max/min bounds.
543-- max/min bounds.
@@ -850,8 +851,8 @@ gbracketIO bef exc aft (Unfold estep einject) (Unfold step1 inject1) =
850--
851--
851{-# INLINE_NORMAL _before #-}
852{-# INLINE_NORMAL _before #-}
852_before :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
853_before :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
853−_before action unf = gbracket (\x -> action x >> return x) (fmap Right)
854+_before action = gbracket (\x -> action x >> return x) (fmap Right)
854− (\_ -> return ()) undefined unf
855+ (\_ -> return ()) undefined
855
856
856-- | Run a side effect before the unfold yields its first element.
857-- | Run a side effect before the unfold yields its first element.
857--
858--
@@ -864,8 +865,7 @@ before action (Unfold step1 inject1) = Unfold step inject
864
865
865 inject x = do
866 inject x = do
866 _ <- action x
867 _ <- action x
867− st <- inject1 x
868+ inject1 x
868− return st
869
869
870 {-# INLINE_LATE step #-}
870 {-# INLINE_LATE step #-}
871 step st = do
871 step st = do
@@ -932,10 +932,10 @@ afterIO action (Unfold step1 inject1) = Unfold step inject
932
932
933{-# INLINE_NORMAL _onException #-}
933{-# INLINE_NORMAL _onException #-}
934_onException :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
934_onException :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
935−_onException action unf =
935+_onException action =
936 gbracket return MC.try
936 gbracket return MC.try
937 (\_ -> return ())
937 (\_ -> return ())
938− (nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
938+ (nilM (\(a, e :: MC.SomeException) -> action a >> MC.throwM e))
939
939
940-- | Run a side effect whenever the unfold aborts due to an exception.
940-- | Run a side effect whenever the unfold aborts due to an exception.
941--
941--
@@ -960,9 +960,9 @@ onException action (Unfold step1 inject1) = Unfold step inject
960
960
961{-# INLINE_NORMAL _finally #-}
961{-# INLINE_NORMAL _finally #-}
962_finally :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
962_finally :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
963−_finally action unf =
963+_finally action =
964 gbracket return MC.try action
964 gbracket return MC.try action
965− (nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
965+ (nilM (\(a, e :: MC.SomeException) -> action a >> MC.throwM e))
966
966
967-- | Run a side effect whenever the unfold stops normally or aborts due to an
967-- | Run a side effect whenever the unfold stops normally or aborts due to an
968-- exception.
968-- exception.
@@ -1019,9 +1019,9 @@ finallyIO action (Unfold step1 inject1) = Unfold step inject
1019{-# INLINE_NORMAL _bracket #-}
1019{-# INLINE_NORMAL _bracket #-}
1020_bracket :: MonadCatch m
1020_bracket :: MonadCatch m
1021 => (a -> m c) -> (c -> m d) -> Unfold m c b -> Unfold m a b
1021 => (a -> m c) -> (c -> m d) -> Unfold m c b -> Unfold m a b
1022−_bracket bef aft unf =
1022+_bracket bef aft =
1023− gbracket bef MC.try aft (nilM (\(a, (e :: MC.SomeException)) -> aft a >>
1023+ gbracket bef MC.try aft (nilM (\(a, e :: MC.SomeException) -> aft a >>
1024− MC.throwM e)) unf
1024+ MC.throwM e))
1025
1025
1026-- | @bracket before after between@ runs the @before@ action and then unfolds
1026-- | @bracket before after between@ runs the @before@ action and then unfolds
1027-- its output using the @between@ unfold. When the @between@ unfold is done or
1027-- its output using the @between@ unfold. When the @between@ unfold is done or
@@ -1094,5 +1094,5 @@ bracketIO bef aft (Unfold step1 inject1) = Unfold step inject
1094{-# INLINE_NORMAL handle #-}
1094{-# INLINE_NORMAL handle #-}
1095handle :: (MonadCatch m, Exception e)
1095handle :: (MonadCatch m, Exception e)
1096 => Unfold m e b -> Unfold m a b -> Unfold m a b
1096 => Unfold m e b -> Unfold m a b -> Unfold m a b
1097−handle exc unf =
1097+handle exc =
1098− gbracket return MC.try (\_ -> return ()) (discardFirst exc) unf
1098+ gbracket return MC.try (\_ -> return ()) (discardFirst exc)
src/Streamly/Internal/Data/Unicode/Stream.hs+5−4
@@ -157,6 +157,7 @@ decodeTable = [
157 12,36,12,12,12,12,12,12,12,12,12,12
157 12,36,12,12,12,12,12,12,12,12,12,12
158 ]
158 ]
159
159
160+{-# NOINLINE utf8d #-}
160utf8d :: A.Array Word8
161utf8d :: A.Array Word8
161utf8d =
162utf8d =
162 unsafePerformIO
163 unsafePerformIO
@@ -180,7 +181,7 @@ unsafePeekElemOff p i = let !x = A.unsafeInlineIO $ peekElemOff p i in x
180decode0 :: Ptr Word8 -> Word8 -> Tuple' DecodeState CodePoint
181decode0 :: Ptr Word8 -> Word8 -> Tuple' DecodeState CodePoint
181decode0 table byte =
182decode0 table byte =
182 let !t = table `unsafePeekElemOff` fromIntegral byte
183 let !t = table `unsafePeekElemOff` fromIntegral byte
183− !codep' = (0xff `shiftR` (fromIntegral t)) .&. fromIntegral byte
184+ !codep' = (0xff `shiftR` fromIntegral t) .&. fromIntegral byte
184 !state' = table `unsafePeekElemOff` (256 + fromIntegral t)
185 !state' = table `unsafePeekElemOff` (256 + fromIntegral t)
185 in assert ((byte > 0x7f || error showByte)
186 in assert ((byte > 0x7f || error showByte)
186 && (state' /= 0 || error (showByte ++ showTable)))
187 && (state' /= 0 || error (showByte ++ showTable)))
@@ -246,7 +247,7 @@ data FreshPoint s a
246decodeUtf8WithD :: Monad m => CodingFailureMode -> Stream m Word8 -> Stream m Char
247decodeUtf8WithD :: Monad m => CodingFailureMode -> Stream m Word8 -> Stream m Char
247decodeUtf8WithD cfm (Stream step state) =
248decodeUtf8WithD cfm (Stream step state) =
248 let A.Array p _ _ = utf8d
249 let A.Array p _ _ = utf8d
249− !ptr = (unsafeForeignPtrToPtr p)
250+ !ptr = unsafeForeignPtrToPtr p
250 in Stream (step' ptr) (FreshPointDecodeInit state)
251 in Stream (step' ptr) (FreshPointDecodeInit state)
251 where
252 where
252 {-# INLINE transliterateOrError #-}
253 {-# INLINE transliterateOrError #-}
@@ -337,7 +338,7 @@ resumeDecodeUtf8EitherD
337 -> Stream m (Either DecodeError Char)
338 -> Stream m (Either DecodeError Char)
338resumeDecodeUtf8EitherD dst codep (Stream step state) =
339resumeDecodeUtf8EitherD dst codep (Stream step state) =
339 let A.Array p _ _ = utf8d
340 let A.Array p _ _ = utf8d
340− !ptr = (unsafeForeignPtrToPtr p)
341+ !ptr = unsafeForeignPtrToPtr p
341 stt =
342 stt =
342 if dst == 0
343 if dst == 0
343 then FreshPointDecodeInit state
344 then FreshPointDecodeInit state
@@ -431,7 +432,7 @@ decodeUtf8ArraysWithD ::
431 -> Stream m Char
432 -> Stream m Char
432decodeUtf8ArraysWithD cfm (Stream step state) =
433decodeUtf8ArraysWithD cfm (Stream step state) =
433 let A.Array p _ _ = utf8d
434 let A.Array p _ _ = utf8d
434− !ptr = (unsafeForeignPtrToPtr p)
435+ !ptr = unsafeForeignPtrToPtr p
435 in Stream (step' ptr) (OuterLoop state Nothing)
436 in Stream (step' ptr) (OuterLoop state Nothing)
436 where
437 where
437 {-# INLINE transliterateOrError #-}
438 {-# INLINE transliterateOrError #-}
src/Streamly/Internal/Network/Socket.hs+7−9
@@ -67,7 +67,7 @@ import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
67import Control.Exception (onException)
67import Control.Exception (onException)
68import Control.Monad.Catch (MonadCatch, finally, MonadMask)
68import Control.Monad.Catch (MonadCatch, finally, MonadMask)
69import Control.Monad.IO.Class (MonadIO(..))
69import Control.Monad.IO.Class (MonadIO(..))
70−import Control.Monad (when)
70+import Control.Monad (forM_, when)
71import Data.Word (Word8)
71import Data.Word (Word8)
72import Foreign.ForeignPtr (withForeignPtr)
72import Foreign.ForeignPtr (withForeignPtr)
73import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
73import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
@@ -164,7 +164,7 @@ listenTuples = Unfold step inject
164 liftIO $ initListener listenQLen spec addr
164 liftIO $ initListener listenQLen spec addr
165
165
166 step listener = do
166 step listener = do
167− r <- liftIO $ (Net.accept listener `onException` Net.close listener)
167+ r <- liftIO (Net.accept listener `onException` Net.close listener)
168 return $ D.Yield r listener
168 return $ D.Yield r listener
169
169
170-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
170-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
@@ -189,9 +189,7 @@ connectCommon SockSpec{..} local remote = withSocketsDo $ do
189
189
190 use sock = do
190 use sock = do
191 mapM_ (\(opt, val) -> setSocketOption sock opt val) sockOpts
191 mapM_ (\(opt, val) -> setSocketOption sock opt val) sockOpts
192− case local of
193− Nothing -> return ()
194− Just addr -> bind sock addr
192+ forM_ local (bind sock)
195 Net.connect sock remote
193 Net.connect sock remote
196
194
197-- | Connect to a remote host using the given socket specification and remote
195-- | Connect to a remote host using the given socket specification and remote
@@ -201,7 +199,7 @@ connectCommon SockSpec{..} local remote = withSocketsDo $ do
201--
199--
202{-# INLINE connect #-}
200{-# INLINE connect #-}
203connect :: SockSpec -> SockAddr -> IO Socket
201connect :: SockSpec -> SockAddr -> IO Socket
204−connect spec remote = connectCommon spec Nothing remote
202+connect spec = connectCommon spec Nothing
205
203
206-- | Connect to a remote host using the given socket specification, a local
204-- | Connect to a remote host using the given socket specification, a local
207-- address to bind to and a remote address to connect to. Returns a connected
205-- address to bind to and a remote address to connect to. Returns a connected
@@ -211,7 +209,7 @@ connect spec remote = connectCommon spec Nothing remote
211--
209--
212{-# INLINE connectFrom #-}
210{-# INLINE connectFrom #-}
213connectFrom :: SockSpec -> SockAddr -> SockAddr -> IO Socket
211connectFrom :: SockSpec -> SockAddr -> SockAddr -> IO Socket
214−connectFrom spec local remote = connectCommon spec (Just local) remote
212+connectFrom spec local = connectCommon spec (Just local)
215
213
216-------------------------------------------------------------------------------
214-------------------------------------------------------------------------------
217-- Listen (Streams)
215-- Listen (Streams)
@@ -224,11 +222,11 @@ recvConnectionTuplesWith tcpListenQ spec addr = S.unfoldrM step Nothing
224 where
222 where
225 step Nothing = do
223 step Nothing = do
226 listener <- liftIO $ initListener tcpListenQ spec addr
224 listener <- liftIO $ initListener tcpListenQ spec addr
227− r <- liftIO $ (Net.accept listener `onException` Net.close listener)
225+ r <- liftIO (Net.accept listener `onException` Net.close listener)
228 return $ Just (r, Just listener)
226 return $ Just (r, Just listener)
229
227
230 step (Just listener) = do
228 step (Just listener) = do
231− r <- liftIO $ (Net.accept listener `onException` Net.close listener)
229+ r <- liftIO (Net.accept listener `onException` Net.close listener)
232 return $ Just (r, Just listener)
230 return $ Just (r, Just listener)
233
231
234-- | Start a TCP stream server that listens for connections on the supplied
232-- | Start a TCP stream server that listens for connections on the supplied