on master help sign in
Clean up hlint warnings

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>

commit1100c23999762393b96913e63984e9b39bfeabd1 authorSanchayan Maity <maitysanchayan@gmail.com> dateSat 11 Jul 2020, 16:59 (6 years ago) parent9148fb7
13 files changed+49−70
.hlint.ignore−11 .hlint.yaml+3 src/Streamly/FileSystem/FDIO.hs+3−4 src/Streamly/Internal/BaseCompat.hs+2−2 src/Streamly/Internal/Control/Monad.hs+1−1 src/Streamly/Internal/Data/Parser/ParserD.hs+2−14 src/Streamly/Internal/Data/Parser/ParserD/Types.hs+2−2 src/Streamly/Internal/Data/Sink.hs+3−3 src/Streamly/Internal/Data/SmallArray/Types.hs+2−1 src/Streamly/Internal/Data/Stream/Prelude.hs+1−1 src/Streamly/Internal/Data/Unfold.hs+18−18 src/Streamly/Internal/Data/Unicode/Stream.hs+5−4 src/Streamly/Internal/Network/Socket.hs+7−9
.hlint.ignore−11
@@ -1,5 +1,3 @@
1−src/Streamly/Internal/BaseCompat.hs
2−src/Streamly/Internal/Control/Monad.hs
31src/Streamly/Internal/Data/Stream/SVar.hs
42src/Streamly/Internal/Data/Stream/Serial.hs
53src/Streamly/Internal/Data/Stream/Zip.hs
@@ -14,16 +12,7 @@ src/Streamly/Internal/Data/Stream/StreamD/Type.hs
1412src/Streamly/Internal/Data/Stream/StreamDK/Type.hs
1513src/Streamly/Internal/Data/Stream/StreamD.hs
1614src/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
2015src/Streamly/Internal/Data/Prim/Array/Types.hs
2116src/Streamly/Internal/Data/SmallArray/Types.hs
22−src/Streamly/Internal/Data/Unfold.hs
2317src/Streamly/Internal/Data/Unicode/Stream.hs
24−src/Streamly/Internal/Memory/Array/Types.hs
2518src/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 @@
1818- ignore: {name: "Use <>"}
1919- ignore: {name: "Use fewer imports"}
2020- ignore: {name: "Use camelCase"}
21+- ignore: {name: "Use <$>"}
22+- ignore: {name: "Use uncurry"}
23+- ignore: {name: "Redundant $!"}
2124
2225
2326# Specify additional command line arguments
src/Streamly/FileSystem/FDIO.hs+3−4
@@ -22,9 +22,9 @@ module Streamly.FileSystem.FDIO
2222 )
2323where
2424
25+import Control.Monad (when)
2526#if !defined(mingw32_HOST_OS)
2627import Control.Concurrent (threadWaitWrite)
27−import Control.Monad (when)
2828import Data.Int (Int64)
2929import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
3030#if __GLASGOW_HASKELL__ >= 802
@@ -193,9 +193,8 @@ writeAll :: FD -> Ptr Word8 -> Int -> IO ()
193193writeAll fd ptr bytes = do
194194 res <- write fd ptr 0 (fromIntegral bytes)
195195 let res' = fromIntegral res
196− if res' < bytes
197− then writeAll fd (ptr `plusPtr` res') (bytes - res')
198− else return ()
196+ when (res' < bytes) $
197+ writeAll fd (ptr `plusPtr` res') (bytes - res')
199198
200199-------------------------------------------------------------------------------
201200-- Vector IO
src/Streamly/Internal/BaseCompat.hs+2−2
@@ -22,6 +22,6 @@ import Data.Coerce (Coercible, coerce)
2222
2323#if !(MIN_VERSION_base(4,9,0))
2424{-# NOINLINE errorWithoutStackTrace #-}
25−errorWithoutStackTrace :: [Char] -> a
26−errorWithoutStackTrace s = error s
25+errorWithoutStackTrace :: String -> a
26+errorWithoutStackTrace = error
2727#endif
src/Streamly/Internal/Control/Monad.hs+1−1
@@ -23,4 +23,4 @@ import Control.Monad.Catch (MonadCatch, catch, SomeException)
2323--
2424{-# INLINE discard #-}
2525discard :: 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
235235
236236 initial = return False
237237
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)
245239
246240{-# INLINABLE all #-}
247241all :: Monad m => (a -> Bool) -> Parser m a Bool
@@ -251,13 +245,7 @@ all predicate = Parser step initial return
251245
252246 initial = return True
253247
254− step s a = return $
255− if s
256− then
257− if predicate a
258− then Partial 0 True
259− else Done 0 False
260− else Done 0 False
248+ step s a = return (if s && predicate a then Partial 0 True else Done 0 False)
261249
262250-------------------------------------------------------------------------------
263251-- Failing Parsers
src/Streamly/Internal/Data/Parser/ParserD/Types.hs+2−2
@@ -263,7 +263,7 @@ yield b = Parser (\_ _ -> pure $ Done 1 b) -- step
263263yieldM :: Monad m => m b -> Parser m a b
264264yieldM b = Parser (\_ _ -> Done 1 <$> b) -- step
265265 (pure ()) -- initial
266− (\_ -> b) -- extract
266+ (const b) -- extract
267267
268268-------------------------------------------------------------------------------
269269-- Sequential applicative
@@ -353,7 +353,7 @@ split_ (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
353353 Error err -> Error err) <$> stepL st a <*> initialR
354354
355355 step (SeqAR st) a = do
356− (\r -> case r of
356+ (\case
357357 Partial n s -> Partial n (SeqAR s)
358358 Continue n s -> Continue n (SeqAR s)
359359 Done n b -> Done n b
src/Streamly/Internal/Data/Sink.hs+3−3
@@ -57,7 +57,7 @@ module Streamly.Internal.Data.Sink
5757 )
5858where
5959
60−import Control.Monad (when, void)
60+import Control.Monad ((>=>), when, void)
6161import Data.Map.Strict (Map)
6262import Prelude
6363 hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
@@ -197,7 +197,7 @@ demux kv = Sink step
197197{-# INLINE unzipM #-}
198198unzipM :: Monad m => (a -> m (b,c)) -> Sink m b -> Sink m c -> Sink m a
199199unzipM 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))
201201
202202-- | Same as 'unzipM' but with a pure unzip function.
203203{-# INLINE unzip #-}
@@ -216,7 +216,7 @@ lmap f (Sink step) = Sink (step . f)
216216-- | Map a monadic function on the input of a 'Sink'.
217217{-# INLINABLE lmapM #-}
218218lmapM :: 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)
220220
221221-- | Filter the input of a 'Sink' using a pure predicate function.
222222{-# INLINABLE lfilter #-}
src/Streamly/Internal/Data/SmallArray/Types.hs+2−1
@@ -679,7 +679,8 @@ instance MonadPlus SmallArray where
679679 mplus = (<|>)
680680
681681zipW :: String -> (a -> b -> c) -> SmallArray a -> SmallArray b -> SmallArray c
682−zipW nm = \f sa sb -> let mn = length sa `min` length sb in
682+zipW nm f sa sb =
683+ let mn = length sa `min` length sb in
683684 createSmallArray mn (die nm "impossible") $ \mc ->
684685 fix ? 0 $ \go i -> when (i < mn) $ do
685686 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
148148
149149{-# INLINE foldr #-}
150150foldr :: (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)
152152
153153-- | Like 'foldlx'', but with a monadic step function.
154154--
src/Streamly/Internal/Data/Unfold.hs+18−18
@@ -126,6 +126,7 @@ module Streamly.Internal.Data.Unfold
126126where
127127
128128import Control.Exception (Exception, mask_)
129+import Control.Monad ((>=>))
129130import Control.Monad.IO.Class (MonadIO(..))
130131import Control.Monad.Trans.Control (MonadBaseControl, liftBaseOp_)
131132import Data.Void (Void)
@@ -173,7 +174,7 @@ lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
173174-- /Internal/
174175{-# INLINE_NORMAL lmapM #-}
175176lmapM :: 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)
177178
178179-- XXX change the signature to the following?
179180-- supply :: a -> Unfold m a b -> Unfold m Void b
@@ -289,7 +290,7 @@ mapM f (Unfold ustep uinject) = Unfold step uinject
289290 case r of
290291 Yield x s -> f x >>= \a -> return $ Yield a s
291292 Skip s -> return $ Skip s
292− Stop -> return $ Stop
293+ Stop -> return Stop
293294
294295{-# INLINE_NORMAL mapMWithInput #-}
295296mapMWithInput :: 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
305306 case r of
306307 Yield x s -> f inp x >>= \a -> return $ Yield a (inp, s)
307308 Skip s -> return $ Skip (inp, s)
308− Stop -> return $ Stop
309+ Stop -> return Stop
309310
310311-------------------------------------------------------------------------------
311312-- Convert streams into unfolds
@@ -437,7 +438,7 @@ replicateM n = Unfold step inject
437438 step (x, i) = return $
438439 if i <= 0
439440 then Stop
440− else Yield x (x, (i - 1))
441+ else Yield x (x, i - 1)
441442
442443-- | Generates an infinite stream repeating the seed.
443444--
@@ -536,7 +537,7 @@ enumerateFromStepIntegral = Unfold step inject
536537 where
537538 inject (from, stride) = from `seq` stride `seq` return (from, stride)
538539 {-# INLINE_LATE step #-}
539− step !(x, stride) = return $ Yield x $! (x + stride, stride)
540+ step (x, stride) = return $ Yield x $! (x + stride, stride)
540541
541542-- We are assuming that "to" is constrained by the type to be within
542543-- max/min bounds.
@@ -850,8 +851,8 @@ gbracketIO bef exc aft (Unfold estep einject) (Unfold step1 inject1) =
850851--
851852{-# INLINE_NORMAL _before #-}
852853_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− (\_ -> return ()) undefined unf
854+_before action = gbracket (\x -> action x >> return x) (fmap Right)
855+ (\_ -> return ()) undefined
855856
856857-- | Run a side effect before the unfold yields its first element.
857858--
@@ -864,8 +865,7 @@ before action (Unfold step1 inject1) = Unfold step inject
864865
865866 inject x = do
866867 _ <- action x
867− st <- inject1 x
868− return st
868+ inject1 x
869869
870870 {-# INLINE_LATE step #-}
871871 step st = do
@@ -932,10 +932,10 @@ afterIO action (Unfold step1 inject1) = Unfold step inject
932932
933933{-# INLINE_NORMAL _onException #-}
934934_onException :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
935−_onException action unf =
935+_onException action =
936936 gbracket return MC.try
937937 (\_ -> return ())
938− (nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
938+ (nilM (\(a, e :: MC.SomeException) -> action a >> MC.throwM e))
939939
940940-- | Run a side effect whenever the unfold aborts due to an exception.
941941--
@@ -960,9 +960,9 @@ onException action (Unfold step1 inject1) = Unfold step inject
960960
961961{-# INLINE_NORMAL _finally #-}
962962_finally :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
963−_finally action unf =
963+_finally action =
964964 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))
966966
967967-- | Run a side effect whenever the unfold stops normally or aborts due to an
968968-- exception.
@@ -1019,9 +1019,9 @@ finallyIO action (Unfold step1 inject1) = Unfold step inject
10191019{-# INLINE_NORMAL _bracket #-}
10201020_bracket :: MonadCatch m
10211021 => (a -> m c) -> (c -> m d) -> Unfold m c b -> Unfold m a b
1022−_bracket bef aft unf =
1023− gbracket bef MC.try aft (nilM (\(a, (e :: MC.SomeException)) -> aft a >>
1024− MC.throwM e)) unf
1022+_bracket bef aft =
1023+ gbracket bef MC.try aft (nilM (\(a, e :: MC.SomeException) -> aft a >>
1024+ MC.throwM e))
10251025
10261026-- | @bracket before after between@ runs the @before@ action and then unfolds
10271027-- 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
10941094{-# INLINE_NORMAL handle #-}
10951095handle :: (MonadCatch m, Exception e)
10961096 => Unfold m e b -> Unfold m a b -> Unfold m a b
1097−handle exc unf =
1098− gbracket return MC.try (\_ -> return ()) (discardFirst exc) unf
1097+handle exc =
1098+ gbracket return MC.try (\_ -> return ()) (discardFirst exc)
src/Streamly/Internal/Data/Unicode/Stream.hs+5−4
@@ -157,6 +157,7 @@ decodeTable = [
157157 12,36,12,12,12,12,12,12,12,12,12,12
158158 ]
159159
160+{-# NOINLINE utf8d #-}
160161utf8d :: A.Array Word8
161162utf8d =
162163 unsafePerformIO
@@ -180,7 +181,7 @@ unsafePeekElemOff p i = let !x = A.unsafeInlineIO $ peekElemOff p i in x
180181decode0 :: Ptr Word8 -> Word8 -> Tuple' DecodeState CodePoint
181182decode0 table byte =
182183 let !t = table `unsafePeekElemOff` fromIntegral byte
183− !codep' = (0xff `shiftR` (fromIntegral t)) .&. fromIntegral byte
184+ !codep' = (0xff `shiftR` fromIntegral t) .&. fromIntegral byte
184185 !state' = table `unsafePeekElemOff` (256 + fromIntegral t)
185186 in assert ((byte > 0x7f || error showByte)
186187 && (state' /= 0 || error (showByte ++ showTable)))
@@ -246,7 +247,7 @@ data FreshPoint s a
246247decodeUtf8WithD :: Monad m => CodingFailureMode -> Stream m Word8 -> Stream m Char
247248decodeUtf8WithD cfm (Stream step state) =
248249 let A.Array p _ _ = utf8d
249− !ptr = (unsafeForeignPtrToPtr p)
250+ !ptr = unsafeForeignPtrToPtr p
250251 in Stream (step' ptr) (FreshPointDecodeInit state)
251252 where
252253 {-# INLINE transliterateOrError #-}
@@ -337,7 +338,7 @@ resumeDecodeUtf8EitherD
337338 -> Stream m (Either DecodeError Char)
338339resumeDecodeUtf8EitherD dst codep (Stream step state) =
339340 let A.Array p _ _ = utf8d
340− !ptr = (unsafeForeignPtrToPtr p)
341+ !ptr = unsafeForeignPtrToPtr p
341342 stt =
342343 if dst == 0
343344 then FreshPointDecodeInit state
@@ -431,7 +432,7 @@ decodeUtf8ArraysWithD ::
431432 -> Stream m Char
432433decodeUtf8ArraysWithD cfm (Stream step state) =
433434 let A.Array p _ _ = utf8d
434− !ptr = (unsafeForeignPtrToPtr p)
435+ !ptr = unsafeForeignPtrToPtr p
435436 in Stream (step' ptr) (OuterLoop state Nothing)
436437 where
437438 {-# INLINE transliterateOrError #-}
src/Streamly/Internal/Network/Socket.hs+7−9
@@ -67,7 +67,7 @@ import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
6767import Control.Exception (onException)
6868import Control.Monad.Catch (MonadCatch, finally, MonadMask)
6969import Control.Monad.IO.Class (MonadIO(..))
70−import Control.Monad (when)
70+import Control.Monad (forM_, when)
7171import Data.Word (Word8)
7272import Foreign.ForeignPtr (withForeignPtr)
7373import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
@@ -164,7 +164,7 @@ listenTuples = Unfold step inject
164164 liftIO $ initListener listenQLen spec addr
165165
166166 step listener = do
167− r <- liftIO $ (Net.accept listener `onException` Net.close listener)
167+ r <- liftIO (Net.accept listener `onException` Net.close listener)
168168 return $ D.Yield r listener
169169
170170-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
@@ -189,9 +189,7 @@ connectCommon SockSpec{..} local remote = withSocketsDo $ do
189189
190190 use sock = do
191191 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)
195193 Net.connect sock remote
196194
197195-- | Connect to a remote host using the given socket specification and remote
@@ -201,7 +199,7 @@ connectCommon SockSpec{..} local remote = withSocketsDo $ do
201199--
202200{-# INLINE connect #-}
203201connect :: SockSpec -> SockAddr -> IO Socket
204−connect spec remote = connectCommon spec Nothing remote
202+connect spec = connectCommon spec Nothing
205203
206204-- | Connect to a remote host using the given socket specification, a local
207205-- 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
211209--
212210{-# INLINE connectFrom #-}
213211connectFrom :: SockSpec -> SockAddr -> SockAddr -> IO Socket
214−connectFrom spec local remote = connectCommon spec (Just local) remote
212+connectFrom spec local = connectCommon spec (Just local)
215213
216214-------------------------------------------------------------------------------
217215-- Listen (Streams)
@@ -224,11 +222,11 @@ recvConnectionTuplesWith tcpListenQ spec addr = S.unfoldrM step Nothing
224222 where
225223 step Nothing = do
226224 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)
228226 return $ Just (r, Just listener)
229227
230228 step (Just listener) = do
231− r <- liftIO $ (Net.accept listener `onException` Net.close listener)
229+ r <- liftIO (Net.accept listener `onException` Net.close listener)
232230 return $ Just (r, Just listener)
233231
234232-- | Start a TCP stream server that listens for connections on the supplied