on master help sign in
Streamly: Internal: Data: Clean up hlint warnings
b5cf9ddSanchayan Maity
.hlint.ignore−6
@@ -1,6 +1,5 @@
1src/Streamly/Internal/BaseCompat.hs
1src/Streamly/Internal/BaseCompat.hs
2src/Streamly/Internal/Control/Monad.hs
2src/Streamly/Internal/Control/Monad.hs
3−src/Streamly/Internal/Data/SVar.hs
4src/Streamly/Internal/Data/Stream/SVar.hs
3src/Streamly/Internal/Data/Stream/SVar.hs
5src/Streamly/Internal/Data/Stream/Serial.hs
4src/Streamly/Internal/Data/Stream/Serial.hs
6src/Streamly/Internal/Data/Stream/Zip.hs
5src/Streamly/Internal/Data/Stream/Zip.hs
@@ -14,16 +13,11 @@ src/Streamly/Internal/Data/Stream/Ahead.hs
14src/Streamly/Internal/Data/Stream/StreamD/Type.hs
13src/Streamly/Internal/Data/Stream/StreamD/Type.hs
15src/Streamly/Internal/Data/Stream/StreamDK/Type.hs
14src/Streamly/Internal/Data/Stream/StreamDK/Type.hs
16src/Streamly/Internal/Data/Stream/StreamD.hs
15src/Streamly/Internal/Data/Stream/StreamD.hs
17−src/Streamly/Internal/Data/SmallArray.hs
18src/Streamly/Internal/Data/Pipe/Types.hs
16src/Streamly/Internal/Data/Pipe/Types.hs
19−src/Streamly/Internal/Data/Pipe.hs
20−src/Streamly/Internal/Data/Sink/Types.hs
21src/Streamly/Internal/Data/Sink.hs
17src/Streamly/Internal/Data/Sink.hs
22src/Streamly/Internal/Data/Zipper/Array.hs
18src/Streamly/Internal/Data/Zipper/Array.hs
23src/Streamly/Internal/Data/Parser/ParserD/Types.hs
19src/Streamly/Internal/Data/Parser/ParserD/Types.hs
24src/Streamly/Internal/Data/Parser/ParserD.hs
20src/Streamly/Internal/Data/Parser/ParserD.hs
25−src/Streamly/Internal/Data/Time/Units.hs
26−src/Streamly/Internal/Data/Prim/Array.hs
27src/Streamly/Internal/Data/Prim/Array/Types.hs
21src/Streamly/Internal/Data/Prim/Array/Types.hs
28src/Streamly/Internal/Data/SmallArray/Types.hs
22src/Streamly/Internal/Data/SmallArray/Types.hs
29src/Streamly/Internal/Data/Unfold.hs
23src/Streamly/Internal/Data/Unfold.hs
src/Streamly/Internal/Data/Fold.hs+2−2
@@ -1182,8 +1182,8 @@ distribute_ fs = Fold step initial extract
1182 step ss a = do
1182 step ss a = do
1183 Prelude.mapM_ (\(Fold s i _) -> i >>= \r -> void (s r a)) ss
1183 Prelude.mapM_ (\(Fold s i _) -> i >>= \r -> void (s r a)) ss
1184 return ss
1184 return ss
1185− extract ss =
1185+ extract =
1186− Prelude.mapM_ (\(Fold _ i e) -> i >>= \r -> e r) ss
1186+ Prelude.mapM_ (\(Fold _ i e) -> i >>= \r -> e r)
1187
1187
1188------------------------------------------------------------------------------
1188------------------------------------------------------------------------------
1189-- Partitioning
1189-- Partitioning
src/Streamly/Internal/Data/Pipe.hs−2
@@ -1,9 +1,7 @@
1−{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
3{-# LANGUAGE ExistentialQuantification #-}
2{-# LANGUAGE ExistentialQuantification #-}
4{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE RankNTypes #-}
6−{-# LANGUAGE RecordWildCards #-}
7{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE ScopedTypeVariables #-}
8
6
9-- |
7-- |
src/Streamly/Internal/Data/Pipe/Types.hs+13−13
@@ -158,18 +158,18 @@ zipWith f (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
158 where
158 where
159
159
160 {-# INLINE drive #-}
160 {-# INLINE drive #-}
161− drive st res queue fConsume fProduce val = do
161+ drive st res queue fConsume fProduce val =
162 case res of
162 case res of
163 Nothing -> goConsume st queue val fConsume fProduce
163 Nothing -> goConsume st queue val fConsume fProduce
164 Just x -> return $
164 Just x -> return $
165 case queue of
165 case queue of
166− Nothing -> (st, Just x, Just $ (Deque [val] []))
166+ Nothing -> (st, Just x, Just $ Deque [val] [])
167 Just q -> (st, Just x, Just $ snoc val q)
167 Just q -> (st, Just x, Just $ snoc val q)
168
168
169 {-# INLINE goConsume #-}
169 {-# INLINE goConsume #-}
170− goConsume stt queue val fConsume stp2 = do
170+ goConsume stt queue val fConsume stp2 =
171 case stt of
171 case stt of
172− Consume st -> do
172+ Consume st ->
173 case queue of
173 case queue of
174 Nothing -> do
174 Nothing -> do
175 r <- fConsume st val
175 r <- fConsume st val
@@ -200,15 +200,15 @@ zipWith f (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
200 where
200 where
201
201
202 {-# INLINE drive #-}
202 {-# INLINE drive #-}
203− drive stt res q fConsume fProduce = do
203+ drive stt res q fConsume fProduce =
204 case res of
204 case res of
205 Nothing -> goProduce stt q fConsume fProduce
205 Nothing -> goProduce stt q fConsume fProduce
206 Just x -> return (stt, Just x, q)
206 Just x -> return (stt, Just x, q)
207
207
208 {-# INLINE goProduce #-}
208 {-# INLINE goProduce #-}
209− goProduce stt queue fConsume fProduce = do
209+ goProduce stt queue fConsume fProduce =
210 case stt of
210 case stt of
211− Consume st -> do
211+ Consume st ->
212 case queue of
212 case queue of
213 -- See yieldOutput. We enter produce mode only when
213 -- See yieldOutput. We enter produce mode only when
214 -- each pipe is either in Produce state or the
214 -- each pipe is either in Produce state or the
@@ -269,7 +269,7 @@ tee (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
269
269
270 state = Tuple' (Consume stateL) (Consume stateR)
270 state = Tuple' (Consume stateL) (Consume stateR)
271
271
272− consume (Tuple' sL sR) a = do
272+ consume (Tuple' sL sR) a =
273 case sL of
273 case sL of
274 Consume st -> do
274 Consume st -> do
275 r <- consumeL st a
275 r <- consumeL st a
@@ -286,9 +286,9 @@ tee (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
286 Continue s -> Continue (Right (Tuple3' (Just a) s sR))
286 Continue s -> Continue (Right (Tuple3' (Just a) s sR))
287 -}
287 -}
288
288
289− produce (Tuple3' (Just a) sL sR) = do
289+ produce (Tuple3' (Just a) sL sR) =
290 case sL of
290 case sL of
291− Consume _ -> do
291+ Consume _ ->
292 case sR of
292 case sR of
293 Consume st -> do
293 Consume st -> do
294 r <- consumeR st a
294 r <- consumeR st a
@@ -309,7 +309,7 @@ tee (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
309 Yield x s -> Yield x (next s)
309 Yield x s -> Yield x (next s)
310 Continue s -> Continue (next s)
310 Continue s -> Continue (next s)
311
311
312− produce (Tuple3' Nothing sL sR) = do
312+ produce (Tuple3' Nothing sL sR) =
313 case sR of
313 case sR of
314 Consume _ -> undefined -- should never occur
314 Consume _ -> undefined -- should never occur
315 Produce st -> do
315 Produce st -> do
@@ -359,7 +359,7 @@ compose (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
359
359
360 state = Tuple' (Consume stateL) (Consume stateR)
360 state = Tuple' (Consume stateL) (Consume stateR)
361
361
362− consume (Tuple' sL sR) a = do
362+ consume (Tuple' sL sR) a =
363 case sL of
363 case sL of
364 Consume stt ->
364 Consume stt ->
365 case sR of
365 case sR of
@@ -392,7 +392,7 @@ compose (Pipe consumeL produceL stateL) (Pipe consumeR produceR stateR) =
392
392
393 -- XXX we need to write the code in mor optimized fashion. Use Continue
393 -- XXX we need to write the code in mor optimized fashion. Use Continue
394 -- more and less yield points.
394 -- more and less yield points.
395− produce (Tuple' sL sR) = do
395+ produce (Tuple' sL sR) =
396 case sL of
396 case sL of
397 Produce st -> do
397 Produce st -> do
398 r <- produceL st
398 r <- produceL st
src/Streamly/Internal/Data/Prim/Array.hs+3−5
@@ -1,8 +1,6 @@
1{-# OPTIONS_GHC -fno-warn-orphans #-}
1{-# OPTIONS_GHC -fno-warn-orphans #-}
2
2
3{-# LANGUAGE CPP #-}
3{-# LANGUAGE CPP #-}
4−{-# LANGUAGE MagicHash #-}
5−{-# LANGUAGE UnboxedTuples #-}
6
4
7#include "inline.hs"
5#include "inline.hs"
8
6
@@ -80,7 +78,7 @@ toStreamD arr = D.Stream step 0
80
78
81{-# INLINE length #-}
79{-# INLINE length #-}
82length :: Prim a => PrimArray a -> Int
80length :: Prim a => PrimArray a -> Int
83−length arr = sizeofPrimArray arr
81+length = sizeofPrimArray
84
82
85{-# INLINE_NORMAL toStreamDRev #-}
83{-# INLINE_NORMAL toStreamDRev #-}
86toStreamDRev :: (Prim a, Monad m) => PrimArray a -> D.Stream m a
84toStreamDRev :: (Prim a, Monad m) => PrimArray a -> D.Stream m a
@@ -139,14 +137,14 @@ fromStreamDN limit str = do
139 marr <- liftIO $ newPrimArray (max limit 0)
137 marr <- liftIO $ newPrimArray (max limit 0)
140 _ <-
138 _ <-
141 D.foldlM'
139 D.foldlM'
142− (\i x -> i `seq` (liftIO $ writePrimArray marr i x) >> return (i + 1))
140+ (\i x -> i `seq` liftIO (writePrimArray marr i x) >> return (i + 1))
143 0 $
141 0 $
144 D.take limit str
142 D.take limit str
145 liftIO $ unsafeFreezePrimArray marr
143 liftIO $ unsafeFreezePrimArray marr
146
144
147{-# INLINE fromStreamD #-}
145{-# INLINE fromStreamD #-}
148fromStreamD :: (MonadIO m, Prim a) => D.Stream m a -> m (PrimArray a)
146fromStreamD :: (MonadIO m, Prim a) => D.Stream m a -> m (PrimArray a)
149−fromStreamD str = D.runFold write str
147+fromStreamD = D.runFold write
150
148
151{-# INLINABLE fromListN #-}
149{-# INLINABLE fromListN #-}
152fromListN :: Prim a => Int -> [a] -> PrimArray a
150fromListN :: Prim a => Int -> [a] -> PrimArray a
src/Streamly/Internal/Data/SVar.hs+6−9
@@ -143,7 +143,7 @@ import Data.Kind (Type)
143#endif
143#endif
144import Data.IORef
144import Data.IORef
145 (IORef, modifyIORef, newIORef, readIORef, writeIORef, atomicModifyIORef)
145 (IORef, modifyIORef, newIORef, readIORef, writeIORef, atomicModifyIORef)
146−import Data.Maybe (fromJust)
146+import Data.Maybe (fromJust, fromMaybe)
147#if __GLASGOW_HASKELL__ < 808
147#if __GLASGOW_HASKELL__ < 808
148import Data.Semigroup ((<>))
148import Data.Semigroup ((<>))
149#endif
149#endif
@@ -704,7 +704,7 @@ collectWorkerPendingLatency cur col = do
704 assert (latCount == 0 || latTime /= 0) (return ())
704 assert (latCount == 0 || latTime /= 0) (return ())
705 let latPair =
705 let latPair =
706 if latCount > 0 && latTime > 0
706 if latCount > 0 && latTime > 0
707− then Just $ (latCount, latTime)
707+ then Just (latCount, latTime)
708 else Nothing
708 else Nothing
709 return (totalCount, latPair)
709 return (totalCount, latPair)
710
710
@@ -748,7 +748,7 @@ collectLatency sv yinfo drain = do
748 case newLatPair of
748 case newLatPair of
749 Nothing -> retWith prevLat
749 Nothing -> retWith prevLat
750 Just (count, time) -> do
750 Just (count, time) -> do
751− let newLat = time `div` (fromIntegral count)
751+ let newLat = time `div` fromIntegral count
752 when (svarInspectMode sv) $ recordMinMaxLatency sv newLat
752 when (svarInspectMode sv) $ recordMinMaxLatency sv newLat
753 -- When we have collected a significant sized batch we compute the
753 -- When we have collected a significant sized batch we compute the
754 -- new latency using that batch and return the new latency,
754 -- new latency using that batch and return the new latency,
@@ -1102,7 +1102,7 @@ sendWithDoorBell q bell msg = do
1102-- | This function is used by the producer threads to queue output for the
1102-- | This function is used by the producer threads to queue output for the
1103-- consumer thread to consume. Returns whether the queue has more space.
1103-- consumer thread to consume. Returns whether the queue has more space.
1104send :: SVar t m a -> ChildEvent a -> IO Int
1104send :: SVar t m a -> ChildEvent a -> IO Int
1105−send sv msg = sendWithDoorBell (outputQueue sv) (outputDoorBell sv) msg
1105+send sv = sendWithDoorBell (outputQueue sv) (outputDoorBell sv)
1106
1106
1107-- There is no bound implemented on the buffer, this is assumed to be low
1107-- There is no bound implemented on the buffer, this is assumed to be low
1108-- traffic.
1108-- traffic.
@@ -1856,10 +1856,7 @@ dispatchWorkerPaced sv = do
1856 let elapsed = fromRelTime64 $ diffAbsTime64 now baseTime
1856 let elapsed = fromRelTime64 $ diffAbsTime64 now baseTime
1857 let latency =
1857 let latency =
1858 if lat == 0
1858 if lat == 0
1859− then
1860− case workerBootstrapLatency yinfo of
1859+ then fromMaybe lat (workerBootstrapLatency yinfo)
1861− Nothing -> lat
1862− Just t -> t
1863 else lat
1860 else lat
1864
1861
1865 return (yieldCount, elapsed, latency)
1862 return (yieldCount, elapsed, latency)
@@ -2349,7 +2346,7 @@ getParallelSVar ss st mrun = do
2349 let bufLim =
2346 let bufLim =
2350 case getMaxBuffer st of
2347 case getMaxBuffer st of
2351 Unlimited -> undefined
2348 Unlimited -> undefined
2352− Limited x -> (fromIntegral x)
2349+ Limited x -> fromIntegral x
2353 remBuf <- newIORef bufLim
2350 remBuf <- newIORef bufLim
2354 pbMVar <- newMVar ()
2351 pbMVar <- newMVar ()
2355
2352
src/Streamly/Internal/Data/Sink/Types.hs+1−1
@@ -21,4 +21,4 @@ where
21-- bit more efficient than a 'Fold' with '()' as the state, especially when
21-- bit more efficient than a 'Fold' with '()' as the state, especially when
22-- 'Sink's are composed with other operations. A Sink can be upgraded to a
22-- 'Sink's are composed with other operations. A Sink can be upgraded to a
23-- 'Fold', but a 'Fold' cannot be converted into a Sink.
23-- 'Fold', but a 'Fold' cannot be converted into a Sink.
24−data Sink m a = Sink (a -> m ())
24+newtype Sink m a = Sink (a -> m ())
src/Streamly/Internal/Data/SmallArray.hs+2−2
@@ -65,7 +65,7 @@ bottomElement = undefined
65
65
66{-# INLINE length #-}
66{-# INLINE length #-}
67length :: SmallArray a -> Int
67length :: SmallArray a -> Int
68−length arr = sizeofSmallArray arr
68+length = sizeofSmallArray
69
69
70{-# INLINE_NORMAL toStreamD #-}
70{-# INLINE_NORMAL toStreamD #-}
71toStreamD :: Monad m => SmallArray a -> D.Stream m a
71toStreamD :: Monad m => SmallArray a -> D.Stream m a
@@ -124,7 +124,7 @@ fromStreamDN limit str = do
124 marr <- liftIO $ newSmallArray (max limit 0) bottomElement
124 marr <- liftIO $ newSmallArray (max limit 0) bottomElement
125 i <-
125 i <-
126 D.foldlM'
126 D.foldlM'
127− (\i x -> i `seq` (liftIO $ writeSmallArray marr i x) >> return (i + 1))
127+ (\i x -> i `seq` liftIO (writeSmallArray marr i x) >> return (i + 1))
128 0 $
128 0 $
129 D.take limit str
129 D.take limit str
130 liftIO $ freezeSmallArray marr 0 i
130 liftIO $ freezeSmallArray marr 0 i
src/Streamly/Internal/Data/SmallArray/Types.hs+3−3
@@ -300,7 +300,7 @@ traverseSmallArrayP
300 => (a -> m b)
300 => (a -> m b)
301 -> SmallArray a
301 -> SmallArray a
302 -> m (SmallArray b)
302 -> m (SmallArray b)
303−traverseSmallArrayP f = \ !ary ->
303+traverseSmallArrayP f !ary =
304 let
304 let
305 !sz = sizeofSmallArray ary
305 !sz = sizeofSmallArray ary
306 go !i !mary
306 go !i !mary
@@ -442,7 +442,7 @@ instance Ord1 SmallArray where
442
442
443-- | Lexicographic ordering. Subject to change between major versions.
443-- | Lexicographic ordering. Subject to change between major versions.
444instance Ord a => Ord (SmallArray a) where
444instance Ord a => Ord (SmallArray a) where
445− compare sa1 sa2 = smallArrayLiftCompare compare sa1 sa2
445+ compare = smallArrayLiftCompare compare
446
446
447instance Foldable SmallArray where
447instance Foldable SmallArray where
448 -- Note: we perform the array lookups eagerly so we won't
448 -- Note: we perform the array lookups eagerly so we won't
@@ -757,7 +757,7 @@ listLiftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> [a] -> Show
757listLiftShowsPrec _ sl _ = sl
757listLiftShowsPrec _ sl _ = sl
758
758
759instance Show a => Show (SmallArray a) where
759instance Show a => Show (SmallArray a) where
760− showsPrec p sa = smallArrayLiftShowsPrec showsPrec showList p sa
760+ showsPrec = smallArrayLiftShowsPrec showsPrec showList
761
761
762#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
762#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
763-- | @since 0.6.4.0
763-- | @since 0.6.4.0
src/Streamly/Internal/Data/Time/Units.hs+6−8
@@ -168,7 +168,7 @@ instance Ord TimeSpec where
168addWithOverflow :: TimeSpec -> TimeSpec -> TimeSpec
168addWithOverflow :: TimeSpec -> TimeSpec -> TimeSpec
169addWithOverflow (TimeSpec s1 ns1) (TimeSpec s2 ns2) =
169addWithOverflow (TimeSpec s1 ns1) (TimeSpec s2 ns2) =
170 let nsum = ns1 + ns2
170 let nsum = ns1 + ns2
171− (s', ns) = if (nsum > tenPower9 || nsum < negate tenPower9)
171+ (s', ns) = if nsum > tenPower9 || nsum < negate tenPower9
172 then nsum `divMod` tenPower9
172 then nsum `divMod` tenPower9
173 else (0, nsum)
173 else (0, nsum)
174 in TimeSpec (s1 + s2 + s') ns
174 in TimeSpec (s1 + s2 + s') ns
@@ -176,12 +176,10 @@ addWithOverflow (TimeSpec s1 ns1) (TimeSpec s2 ns2) =
176-- make sure both sec and nsec have the same sign
176-- make sure both sec and nsec have the same sign
177{-# INLINE adjustSign #-}
177{-# INLINE adjustSign #-}
178adjustSign :: TimeSpec -> TimeSpec
178adjustSign :: TimeSpec -> TimeSpec
179−adjustSign (t@(TimeSpec s ns)) =
179+adjustSign t@(TimeSpec s ns)
180− if (s > 0 && ns < 0)
181− then TimeSpec (s - 1) (ns + tenPower9)
180+ | s > 0 && ns < 0 = TimeSpec (s - 1) (ns + tenPower9)
182− else if (s < 0 && ns > 0)
183− then TimeSpec (s + 1) (ns - tenPower9)
181+ | s < 0 && ns > 0 = TimeSpec (s + 1) (ns - tenPower9)
184− else t
182+ | otherwise = t
185
183
186{-# INLINE timeSpecToInteger #-}
184{-# INLINE timeSpecToInteger #-}
187timeSpecToInteger :: TimeSpec -> Integer
185timeSpecToInteger :: TimeSpec -> Integer
@@ -193,7 +191,7 @@ instance Num TimeSpec where
193
191
194 -- XXX will this be more optimal if imlemented without "negate"?
192 -- XXX will this be more optimal if imlemented without "negate"?
195 {-# INLINE (-) #-}
193 {-# INLINE (-) #-}
196− t1 - t2 = t1 + (negate t2)
194+ t1 - t2 = t1 + negate t2
197 t1 * t2 = fromInteger $ timeSpecToInteger t1 * timeSpecToInteger t2
195 t1 * t2 = fromInteger $ timeSpecToInteger t1 * timeSpecToInteger t2
198
196
199 {-# INLINE negate #-}
197 {-# INLINE negate #-}