on master help sign in
Cleanup hlint warnings

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

commitc9eff7e2715ffd88a0cdca2ea8e8acc29ac7b753 authorSanchayan Maity <maitysanchayan@gmail.com> dateSun 3 May 2020, 13:01 (6 years ago) parenta4b51db
4 files changed+45−48
src/Streamly/Internal/Data/Array.hs+6−6 src/Streamly/Internal/Data/Fold.hs+8−11 src/Streamly/Internal/Data/Fold/Types.hs+9−9 src/Streamly/Internal/Prelude.hs+22−22
src/Streamly/Internal/Data/Array.hs+6−6
@@ -77,11 +77,11 @@ toStreamD arr = D.Stream step 0
7777 step _ (I# i) =
7878 return $
7979 case Exts.indexArray# (array# arr) i of
80− (# x #) -> D.Yield x ((I# i) + 1)
80+ (# x #) -> D.Yield x (I# i + 1)
8181
8282{-# INLINE length #-}
8383length :: Array a -> Int
84−length arr = sizeofArray arr
84+length = sizeofArray
8585
8686{-# INLINE_NORMAL toStreamDRev #-}
8787toStreamDRev :: Monad m => Array a -> D.Stream m a
@@ -93,7 +93,7 @@ toStreamDRev arr = D.Stream step (length arr - 1)
9393 step _ (I# i) =
9494 return $
9595 case Exts.indexArray# (array# arr) i of
96− (# x #) -> D.Yield x ((I# i) - 1)
96+ (# x #) -> D.Yield x (I# i - 1)
9797
9898{-# INLINE_NORMAL foldl' #-}
9999foldl' :: (b -> a -> b) -> b -> Array a -> b
@@ -143,14 +143,14 @@ fromStreamDN limit str = do
143143 marr <- liftIO $ newArray (max limit 0) bottomElement
144144 i <-
145145 D.foldlM'
146− (\i x -> i `seq` (liftIO $ writeArray marr i x) >> return (i + 1))
146+ (\i x -> i `seq` liftIO $ writeArray marr i x >> return (i + 1))
147147 0 $
148148 D.take limit str
149149 liftIO $ freezeArray marr 0 i
150150
151151{-# INLINE fromStreamD #-}
152152fromStreamD :: MonadIO m => D.Stream m a -> m (Array a)
153−fromStreamD str = D.runFold write str
153+fromStreamD = D.runFold write
154154
155155{-# INLINABLE fromListN #-}
156156fromListN :: Int -> [a] -> Array a
@@ -197,7 +197,7 @@ read = Unfold step inject
197197 inject arr = return (arr, 0)
198198 step (arr, i)
199199 | i == length arr = return D.Stop
200− step (arr, (I# i)) =
200+ step (arr, I# i) =
201201 return $
202202 case Exts.indexArray# (array# arr) i of
203203 (# x #) -> D.Yield x (arr, I# i + 1)
src/Streamly/Internal/Data/Fold.hs+8−11
@@ -3,7 +3,6 @@
33{-# LANGUAGE ExistentialQuantification #-}
44{-# LANGUAGE FlexibleContexts #-}
55{-# LANGUAGE RankNTypes #-}
6−{-# LANGUAGE RecordWildCards #-}
76{-# LANGUAGE ScopedTypeVariables #-}
87
98-- |
@@ -209,7 +208,7 @@ module Streamly.Internal.Data.Fold
209208 )
210209where
211210
212−import Control.Monad (void)
211+import Control.Monad (join, void)
213212import Control.Monad.IO.Class (MonadIO(..))
214213import Data.Functor.Identity (Identity(..))
215214import Data.Int (Int64)
@@ -308,9 +307,7 @@ generally = hoist (return . runIdentity)
308307sequence :: Monad m => Fold m a (m b) -> Fold m a b
309308sequence (Fold step initial extract) = Fold step initial extract'
310309 where
311− extract' x = do
312− act <- extract x
313− act >>= return
310+ extract' x = join (extract x)
314311
315312-- | Map a monadic function on the output of a fold.
316313--
@@ -937,7 +934,7 @@ splitAt n (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
937934 step (Tuple3' i xL xR) input =
938935 if i > 0
939936 then stepL xL input >>= (\a -> return (Tuple3' (i - 1) a xR))
940− else stepR xR input >>= (\b -> return (Tuple3' i xL b))
937+ else stepR xR input >>= (return . Tuple3' i xL)
941938
942939 extract (Tuple3' _ a b) = (,) <$> extractL a <*> extractR b
943940
@@ -1135,7 +1132,7 @@ foldCons (Fold stepL beginL doneL) (Fold stepR beginR doneR) =
11351132
11361133 begin = Tuple' <$> beginL <*> beginR
11371134 step (Tuple' xL xR) a = Tuple' <$> stepL xL a <*> stepR xR a
1138− done (Tuple' xL xR) = (:) <$> (doneL xL) <*> (doneR xR)
1135+ done (Tuple' xL xR) = (:) <$> doneL xL <*> doneR xR
11391136
11401137-- XXX use "List" instead of "[]"?, use Array for output to scale it to a large
11411138-- number of consumers? For polymorphic case a vector could be helpful. For
@@ -1174,7 +1171,7 @@ distribute_ fs = Fold step initial extract
11741171 initial = Prelude.mapM (\(Fold s i e) ->
11751172 i >>= \r -> return (Fold s (return r) e)) fs
11761173 step ss a = do
1177− Prelude.mapM_ (\(Fold s i _) -> i >>= \r -> s r a >> return ()) ss
1174+ Prelude.mapM_ (\(Fold s i _) -> i >>= \r -> void (s r a)) ss
11781175 return ss
11791176 extract ss = do
11801177 Prelude.mapM_ (\(Fold _ i e) -> i >>= \r -> e r) ss
@@ -1413,7 +1410,7 @@ demuxWith_ f kv = Fold step initial extract
14131410
14141411 where
14151412
1416− initial = do
1413+ initial =
14171414 Prelude.mapM (\(Fold s i e) ->
14181415 i >>= \r -> return (Fold s (return r) e)) kv
14191416 step mp a
@@ -1426,7 +1423,7 @@ demuxWith_ f kv = Fold step initial extract
14261423 Just (Fold step' acc _) -> do
14271424 _ <- acc >>= \x -> step' x a'
14281425 return mp
1429− extract mp = Prelude.mapM_ (\(Fold _ acc e) -> acc >>= e) mp
1426+ extract = Prelude.mapM_ (\(Fold _ acc e) -> acc >>= e)
14301427
14311428-- | Given a stream of key value pairs and a map from keys to folds, fold the
14321429-- values for each key using the corresponding folds, discarding the outputs.
@@ -1622,7 +1619,7 @@ toParallelSVar svar winfo = Fold step initial extract
16221619 decrementBufferLimit svar
16231620 void $ send svar (ChildYield x)
16241621
1625− extract () = liftIO $ do
1622+ extract () = liftIO $
16261623 sendStop svar winfo
16271624
16281625{-# INLINE toParallelSVarLimited #-}
src/Streamly/Internal/Data/Fold/Types.hs+9−9
@@ -403,7 +403,7 @@ ltake :: Monad m => Int -> Fold m a b -> Fold m a b
403403ltake n (Fold step initial done) = Fold step' initial' done'
404404 where
405405 initial' = fmap (Tuple' 0) initial
406− step' (Tuple' i r) a = do
406+ step' (Tuple' i r) a =
407407 if i < n
408408 then do
409409 res <- step r a
@@ -419,9 +419,9 @@ ltakeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
419419ltakeWhile predicate (Fold step initial done) = Fold step' initial' done'
420420 where
421421 initial' = fmap Left' initial
422− step' (Left' r) a = do
422+ step' (Left' r) a =
423423 if predicate a
424− then fmap Left' $ step r a
424+ then Left' <$> step r a
425425 else return (Right' r)
426426 step' r _ = return r
427427 done' (Left' r) = done r
@@ -464,7 +464,7 @@ runStep :: Monad m => Fold m a b -> a -> m (Fold m a b)
464464runStep (Fold step initial extract) a = do
465465 i <- initial
466466 r <- step i a
467− return $ (Fold step (return r) extract)
467+ return $ Fold step (return r) extract
468468
469469------------------------------------------------------------------------------
470470-- Parsing
@@ -483,8 +483,8 @@ lchunksOf n (Fold step1 initial1 extract1) (Fold step2 initial2 extract2) =
483483
484484 where
485485
486− initial' = (Tuple3' 0) <$> initial1 <*> initial2
487− step' (Tuple3' i r1 r2) a = do
486+ initial' = Tuple3' 0 <$> initial1 <*> initial2
487+ step' (Tuple3' i r1 r2) a =
488488 if i < n
489489 then do
490490 res <- step1 r1 a
@@ -508,8 +508,8 @@ lchunksOf2 n (Fold step1 initial1 extract1) (Fold2 step2 inject2 extract2) =
508508
509509 where
510510
511− inject' x = (Tuple3' 0) <$> initial1 <*> inject2 x
512− step' (Tuple3' i r1 r2) a = do
511+ inject' x = Tuple3' 0 <$> initial1 <*> inject2 x
512+ step' (Tuple3' i r1 r2) a =
513513 if i < n
514514 then do
515515 res <- step1 r1 a
@@ -580,7 +580,7 @@ lsessionsOf n (Fold step1 initial1 extract1) (Fold step2 initial2 extract2) =
580580 r2 <- liftIO $ takeMVar mv2
581581 res <- case r2 of
582582 Left _ -> return r2
583− Right x -> fmap Right $ step2 x res1
583+ Right x -> Right <$> step2 x res1
584584 liftIO $ putMVar mv2 res
585585 timerThread mv1 mv2
586586
src/Streamly/Internal/Prelude.hs+22−22
@@ -1579,7 +1579,7 @@ isPrefixOf m1 m2 = D.isPrefixOf (toStreamD m1) (toStreamD m2)
15791579--
15801580{-# INLINE isSuffixOf #-}
15811581isSuffixOf :: (Monad m, Eq a) => SerialT m a -> SerialT m a -> m Bool
1582−isSuffixOf suffix stream = isPrefixOf (reverse suffix) (reverse stream)
1582+isSuffixOf suffix stream = reverse suffix `isPrefixOf` reverse stream
15831583
15841584-- | Returns 'True' if the first stream is an infix of the second. A stream is
15851585-- considered an infix of itself.
@@ -1753,7 +1753,7 @@ toListRev = D.toListRev . toStreamD
17531753{-# DEPRECATED toHandle
17541754 "Please use Streamly.FileSystem.Handle module (see the changelog)" #-}
17551755toHandle :: MonadIO m => IO.Handle -> SerialT m String -> m ()
1756−toHandle h m = go m
1756+toHandle h = go
17571757 where
17581758 go m1 =
17591759 let stop = return ()
@@ -3023,7 +3023,7 @@ concatMapIterateWith
30233023 -> (a -> t m a)
30243024 -> t m a
30253025 -> t m a
3026−concatMapIterateWith combine f xs = concatMapWith combine go xs
3026+concatMapIterateWith combine f = concatMapWith combine go
30273027 where
30283028 go x = yield x `combine` concatMapWith combine go (f x)
30293029
@@ -3058,7 +3058,7 @@ concatMapTreeWith
30583058 -> (a -> t m (Either a b))
30593059 -> t m (Either a b) -- Should be t m a?
30603060 -> t m (Either a b)
3061−concatMapTreeWith combine f xs = concatMapWith combine go xs
3061+concatMapTreeWith combine f = concatMapWith combine go
30623062 where
30633063 go (Left tree) = yield (Left tree) `combine` concatMapWith combine go (f tree)
30643064 go (Right leaf) = yield $ Right leaf
@@ -3959,7 +3959,7 @@ pollCounts ::
39593959pollCounts predicate transf f xs =
39603960 D.fromStreamD
39613961 $ D.pollCounts predicate (D.toStreamD . transf . D.fromStreamD) f
3962− $ (D.toStreamD xs)
3962+ $ D.toStreamD xs
39633963
39643964-- | Calls the supplied function with the number of elements consumed
39653965-- every @n@ seconds. The given function is run in a separate thread
@@ -3985,7 +3985,7 @@ tapRate ::
39853985 -> (Int -> m b)
39863986 -> t m a
39873987 -> t m a
3988−tapRate n f xs = D.fromStreamD $ D.tapRate n f $ (D.toStreamD xs)
3988+tapRate n f xs = D.fromStreamD $ D.tapRate n f $ D.toStreamD xs
39893989
39903990-- | Apply a monadic function to each element flowing through the stream and
39913991-- discard the results.
@@ -4186,7 +4186,7 @@ classifySessionsBy
41864186 -> t m (k, b) -- ^ session key, fold result
41874187classifySessionsBy tick timeout reset ejectPred
41884188 (Fold step initial extract) str =
4189− concatMap (\session -> sessionOutputStream session)
4189+ concatMap sessionOutputStream
41904190 $ scanlM' sstep szero stream
41914191
41924192 where
@@ -4213,7 +4213,7 @@ classifySessionsBy tick timeout reset ejectPred
42134213 -- We use the first strategy as of now.
42144214
42154215 -- Got a new stream input element
4216− sstep (session@SessionState{..}) (Just (key, value, timestamp)) = do
4216+ sstep session@SessionState{..} (Just (key, value, timestamp)) = do
42174217 -- XXX we should use a heap in pinned memory to scale it to a large
42184218 -- size
42194219 --
@@ -4273,7 +4273,7 @@ classifySessionsBy tick timeout reset ejectPred
42734273 -- Insert the new session in heap
42744274 let expiry = addToAbsTime timestamp timeoutMs
42754275 hp' = H.insert (Entry expiry key) hp
4276− in return $ (hp', mp, out, (cnt + 1))
4276+ in return (hp', mp, out, cnt + 1)
42774277 -- updating old entry
42784278 Just _ -> return vars
42794279
@@ -4288,7 +4288,7 @@ classifySessionsBy tick timeout reset ejectPred
42884288 }
42894289
42904290 -- Got a timer tick event
4291− sstep (sessionState@SessionState{..}) Nothing =
4291+ sstep sessionState@SessionState{..} Nothing =
42924292 let curTime = addToAbsTime sessionCurTime tickMs
42934293 in ejectExpired sessionState curTime
42944294
@@ -4302,12 +4302,12 @@ classifySessionsBy tick timeout reset ejectPred
43024302 sess <- extract acc
43034303 let out1 = (key, fromEither sess) `K.cons` out
43044304 let mp1 = Map.delete key mp
4305− return (hp, mp1, out1, (cnt - 1))
4305+ return (hp, mp1, out1, cnt - 1)
43064306
43074307 ejectOne (hp, mp, out, !cnt) = do
43084308 let hres = H.uncons hp
43094309 case hres of
4310− Just (Entry expiry key, hp1) -> do
4310+ Just (Entry expiry key, hp1) ->
43114311 case Map.lookup key mp of
43124312 Nothing -> ejectOne (hp1, mp, out, cnt)
43134313 Just (Tuple' latestTS acc) -> do
@@ -4322,7 +4322,7 @@ classifySessionsBy tick timeout reset ejectPred
43224322 assert (Map.null mp) (return ())
43234323 return (hp, mp, out, cnt)
43244324
4325− ejectExpired (session@SessionState{..}) curTime = do
4325+ ejectExpired session@SessionState{..} curTime = do
43264326 (hp', mp', out, count) <-
43274327 ejectLoop sessionTimerHeap sessionKeyValueMap K.nil sessionCount
43284328 return $ session
@@ -4339,14 +4339,14 @@ classifySessionsBy tick timeout reset ejectPred
43394339 let hres = H.uncons hp
43404340 case hres of
43414341 Just (Entry expiry key, hp1) -> do
4342− (eject, force) <- do
4342+ (eject, force) <-
43434343 if curTime >= expiry
43444344 then return (True, False)
43454345 else do
43464346 r <- ejectPred cnt
43474347 return (r, r)
43484348 if eject
4349− then do
4349+ then
43504350 case Map.lookup key mp of
43514351 Nothing -> ejectLoop hp1 mp out cnt
43524352 Just (Tuple' latestTS acc) -> do
@@ -4392,8 +4392,8 @@ classifyKeepAliveSessions
43924392 -> Fold m a (Either b b) -- ^ Fold to be applied to session payload data
43934393 -> t m (k, a, AbsTime) -- ^ session key, data, timestamp
43944394 -> t m (k, b)
4395−classifyKeepAliveSessions timeout ejectPred =
4396− classifySessionsBy 1 timeout True ejectPred
4395+classifyKeepAliveSessions timeout =
4396+ classifySessionsBy 1 timeout True
43974397
43984398------------------------------------------------------------------------------
43994399-- Keyed tumbling windows
@@ -4450,8 +4450,8 @@ classifySessionsOf
44504450 -> Fold m a (Either b b) -- ^ Fold to be applied to session events
44514451 -> t m (k, a, AbsTime) -- ^ session key, data, timestamp
44524452 -> t m (k, b)
4453−classifySessionsOf interval ejectPred =
4454− classifySessionsBy 1 interval False ejectPred
4453+classifySessionsOf interval =
4454+ classifySessionsBy 1 interval False
44554455
44564456------------------------------------------------------------------------------
44574457-- Exceptions
@@ -4526,7 +4526,7 @@ finallyIO action xs = D.fromStreamD $ D.finallyIO action $ D.toStreamD xs
45264526bracket :: (IsStream t, MonadCatch m)
45274527 => m b -> (b -> m c) -> (b -> t m a) -> t m a
45284528bracket bef aft bet = D.fromStreamD $
4529− D.bracket bef aft (\x -> toStreamD $ bet x)
4529+ D.bracket bef aft (toStreamD . bet)
45304530
45314531-- | Run the first action before the stream starts and remember its output,
45324532-- generate a stream using the output, run the second action using the
@@ -4539,7 +4539,7 @@ bracket bef aft bet = D.fromStreamD $
45394539bracketIO :: (IsStream t, MonadAsync m, MonadCatch m)
45404540 => m b -> (b -> m c) -> (b -> t m a) -> t m a
45414541bracketIO bef aft bet = D.fromStreamD $
4542− D.bracketIO bef aft (\x -> toStreamD $ bet x)
4542+ D.bracketIO bef aft (toStreamD . bet)
45434543
45444544-- | When evaluating a stream if an exception occurs, stream evaluation aborts
45454545-- and the specified exception handler is run with the exception as argument.
@@ -4549,7 +4549,7 @@ bracketIO bef aft bet = D.fromStreamD $
45494549handle :: (IsStream t, MonadCatch m, Exception e)
45504550 => (e -> t m a) -> t m a -> t m a
45514551handle handler xs =
4552− D.fromStreamD $ D.handle (\e -> D.toStreamD $ handler e) $ D.toStreamD xs
4552+ D.fromStreamD $ D.handle (D.toStreamD . handler) $ D.toStreamD xs
45534553
45544554------------------------------------------------------------------------------
45554555-- Generalize the underlying monad