mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 19:47:10 +03:00
Clean up hlint warnings
Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
This commit is contained in:
parent
9148fb7308
commit
1100c23999
@ -1,5 +1,3 @@
|
||||
src/Streamly/Internal/BaseCompat.hs
|
||||
src/Streamly/Internal/Control/Monad.hs
|
||||
src/Streamly/Internal/Data/Stream/SVar.hs
|
||||
src/Streamly/Internal/Data/Stream/Serial.hs
|
||||
src/Streamly/Internal/Data/Stream/Zip.hs
|
||||
@ -14,16 +12,7 @@ src/Streamly/Internal/Data/Stream/StreamD/Type.hs
|
||||
src/Streamly/Internal/Data/Stream/StreamDK/Type.hs
|
||||
src/Streamly/Internal/Data/Stream/StreamD.hs
|
||||
src/Streamly/Internal/Data/Pipe/Types.hs
|
||||
src/Streamly/Internal/Data/Sink.hs
|
||||
src/Streamly/Internal/Data/Parser/ParserD/Types.hs
|
||||
src/Streamly/Internal/Data/Parser/ParserD.hs
|
||||
src/Streamly/Internal/Data/Prim/Array/Types.hs
|
||||
src/Streamly/Internal/Data/SmallArray/Types.hs
|
||||
src/Streamly/Internal/Data/Unfold.hs
|
||||
src/Streamly/Internal/Data/Unicode/Stream.hs
|
||||
src/Streamly/Internal/Memory/Array/Types.hs
|
||||
src/Streamly/Internal/Mutable/Prim/Var.hs
|
||||
src/Streamly/Internal/Network/Socket.hs
|
||||
src/Streamly/Internal/Data/Stream/Prelude.hs
|
||||
src/Streamly/FileSystem/FDIO.hs
|
||||
src/Streamly/Data/Unfold.hs
|
||||
|
@ -18,6 +18,9 @@
|
||||
- ignore: {name: "Use <>"}
|
||||
- ignore: {name: "Use fewer imports"}
|
||||
- ignore: {name: "Use camelCase"}
|
||||
- ignore: {name: "Use <$>"}
|
||||
- ignore: {name: "Use uncurry"}
|
||||
- ignore: {name: "Redundant $!"}
|
||||
|
||||
|
||||
# Specify additional command line arguments
|
||||
|
@ -22,9 +22,9 @@ module Streamly.FileSystem.FDIO
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad (when)
|
||||
#if !defined(mingw32_HOST_OS)
|
||||
import Control.Concurrent (threadWaitWrite)
|
||||
import Control.Monad (when)
|
||||
import Data.Int (Int64)
|
||||
import Foreign.C.Error (throwErrnoIfMinus1RetryMayBlock)
|
||||
#if __GLASGOW_HASKELL__ >= 802
|
||||
@ -193,9 +193,8 @@ writeAll :: FD -> Ptr Word8 -> Int -> IO ()
|
||||
writeAll fd ptr bytes = do
|
||||
res <- write fd ptr 0 (fromIntegral bytes)
|
||||
let res' = fromIntegral res
|
||||
if res' < bytes
|
||||
then writeAll fd (ptr `plusPtr` res') (bytes - res')
|
||||
else return ()
|
||||
when (res' < bytes) $
|
||||
writeAll fd (ptr `plusPtr` res') (bytes - res')
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Vector IO
|
||||
|
@ -22,6 +22,6 @@ import Data.Coerce (Coercible, coerce)
|
||||
|
||||
#if !(MIN_VERSION_base(4,9,0))
|
||||
{-# NOINLINE errorWithoutStackTrace #-}
|
||||
errorWithoutStackTrace :: [Char] -> a
|
||||
errorWithoutStackTrace s = error s
|
||||
errorWithoutStackTrace :: String -> a
|
||||
errorWithoutStackTrace = error
|
||||
#endif
|
||||
|
@ -23,4 +23,4 @@ import Control.Monad.Catch (MonadCatch, catch, SomeException)
|
||||
--
|
||||
{-# INLINE discard #-}
|
||||
discard :: MonadCatch m => m b -> m ()
|
||||
discard action = (void $ action) `catch` (\(_ :: SomeException) -> return ())
|
||||
discard action = void action `catch` (\(_ :: SomeException) -> return ())
|
||||
|
@ -235,13 +235,7 @@ any predicate = Parser step initial return
|
||||
|
||||
initial = return False
|
||||
|
||||
step s a = return $
|
||||
if s
|
||||
then Done 0 True
|
||||
else
|
||||
if predicate a
|
||||
then Done 0 True
|
||||
else Partial 0 False
|
||||
step s a = return (if s || predicate a then Done 0 True else Partial 0 False)
|
||||
|
||||
{-# INLINABLE all #-}
|
||||
all :: Monad m => (a -> Bool) -> Parser m a Bool
|
||||
@ -251,13 +245,7 @@ all predicate = Parser step initial return
|
||||
|
||||
initial = return True
|
||||
|
||||
step s a = return $
|
||||
if s
|
||||
then
|
||||
if predicate a
|
||||
then Partial 0 True
|
||||
else Done 0 False
|
||||
else Done 0 False
|
||||
step s a = return (if s && predicate a then Partial 0 True else Done 0 False)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Failing Parsers
|
||||
|
@ -263,7 +263,7 @@ yield b = Parser (\_ _ -> pure $ Done 1 b) -- step
|
||||
yieldM :: Monad m => m b -> Parser m a b
|
||||
yieldM b = Parser (\_ _ -> Done 1 <$> b) -- step
|
||||
(pure ()) -- initial
|
||||
(\_ -> b) -- extract
|
||||
(const b) -- extract
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Sequential applicative
|
||||
@ -353,7 +353,7 @@ split_ (Parser stepL initialL extractL) (Parser stepR initialR extractR) =
|
||||
Error err -> Error err) <$> stepL st a <*> initialR
|
||||
|
||||
step (SeqAR st) a = do
|
||||
(\r -> case r of
|
||||
(\case
|
||||
Partial n s -> Partial n (SeqAR s)
|
||||
Continue n s -> Continue n (SeqAR s)
|
||||
Done n b -> Done n b
|
||||
|
@ -57,7 +57,7 @@ module Streamly.Internal.Data.Sink
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad (when, void)
|
||||
import Control.Monad ((>=>), when, void)
|
||||
import Data.Map.Strict (Map)
|
||||
import Prelude
|
||||
hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
|
||||
@ -197,7 +197,7 @@ demux kv = Sink step
|
||||
{-# INLINE unzipM #-}
|
||||
unzipM :: Monad m => (a -> m (b,c)) -> Sink m b -> Sink m c -> Sink m a
|
||||
unzipM f (Sink stepB) (Sink stepC) =
|
||||
Sink (\a -> f a >>= \(b,c) -> stepB b >> stepC c)
|
||||
Sink (f >=> (\(b, c) -> stepB b >> stepC c))
|
||||
|
||||
-- | Same as 'unzipM' but with a pure unzip function.
|
||||
{-# INLINE unzip #-}
|
||||
@ -216,7 +216,7 @@ lmap f (Sink step) = Sink (step . f)
|
||||
-- | Map a monadic function on the input of a 'Sink'.
|
||||
{-# INLINABLE lmapM #-}
|
||||
lmapM :: Monad m => (a -> m b) -> Sink m b -> Sink m a
|
||||
lmapM f (Sink step) = Sink (\x -> f x >>= step)
|
||||
lmapM f (Sink step) = Sink (f >=> step)
|
||||
|
||||
-- | Filter the input of a 'Sink' using a pure predicate function.
|
||||
{-# INLINABLE lfilter #-}
|
||||
|
@ -679,7 +679,8 @@ instance MonadPlus SmallArray where
|
||||
mplus = (<|>)
|
||||
|
||||
zipW :: String -> (a -> b -> c) -> SmallArray a -> SmallArray b -> SmallArray c
|
||||
zipW nm = \f sa sb -> let mn = length sa `min` length sb in
|
||||
zipW nm f sa sb =
|
||||
let mn = length sa `min` length sb in
|
||||
createSmallArray mn (die nm "impossible") $ \mc ->
|
||||
fix ? 0 $ \go i -> when (i < mn) $ do
|
||||
x <- indexSmallArrayM sa i
|
||||
|
@ -148,7 +148,7 @@ foldrMx step final project m = D.foldrMx step final project $ D.toStreamD m
|
||||
|
||||
{-# INLINE foldr #-}
|
||||
foldr :: (Monad m, IsStream t) => (a -> b -> b) -> b -> t m a -> m b
|
||||
foldr f z = foldrM (\a b -> b >>= return . f a) (return z)
|
||||
foldr f z = foldrM (\a b -> f a <$> b) (return z)
|
||||
|
||||
-- | Like 'foldlx'', but with a monadic step function.
|
||||
--
|
||||
|
@ -126,6 +126,7 @@ module Streamly.Internal.Data.Unfold
|
||||
where
|
||||
|
||||
import Control.Exception (Exception, mask_)
|
||||
import Control.Monad ((>=>))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Control.Monad.Trans.Control (MonadBaseControl, liftBaseOp_)
|
||||
import Data.Void (Void)
|
||||
@ -173,7 +174,7 @@ lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
|
||||
-- /Internal/
|
||||
{-# INLINE_NORMAL lmapM #-}
|
||||
lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
|
||||
lmapM f (Unfold ustep uinject) = Unfold ustep (\x -> f x >>= uinject)
|
||||
lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
|
||||
|
||||
-- XXX change the signature to the following?
|
||||
-- supply :: a -> Unfold m a b -> Unfold m Void b
|
||||
@ -289,7 +290,7 @@ mapM f (Unfold ustep uinject) = Unfold step uinject
|
||||
case r of
|
||||
Yield x s -> f x >>= \a -> return $ Yield a s
|
||||
Skip s -> return $ Skip s
|
||||
Stop -> return $ Stop
|
||||
Stop -> return Stop
|
||||
|
||||
{-# INLINE_NORMAL mapMWithInput #-}
|
||||
mapMWithInput :: 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
|
||||
case r of
|
||||
Yield x s -> f inp x >>= \a -> return $ Yield a (inp, s)
|
||||
Skip s -> return $ Skip (inp, s)
|
||||
Stop -> return $ Stop
|
||||
Stop -> return Stop
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Convert streams into unfolds
|
||||
@ -437,7 +438,7 @@ replicateM n = Unfold step inject
|
||||
step (x, i) = return $
|
||||
if i <= 0
|
||||
then Stop
|
||||
else Yield x (x, (i - 1))
|
||||
else Yield x (x, i - 1)
|
||||
|
||||
-- | Generates an infinite stream repeating the seed.
|
||||
--
|
||||
@ -536,7 +537,7 @@ enumerateFromStepIntegral = Unfold step inject
|
||||
where
|
||||
inject (from, stride) = from `seq` stride `seq` return (from, stride)
|
||||
{-# INLINE_LATE step #-}
|
||||
step !(x, stride) = return $ Yield x $! (x + stride, stride)
|
||||
step (x, stride) = return $ Yield x $! (x + stride, stride)
|
||||
|
||||
-- We are assuming that "to" is constrained by the type to be within
|
||||
-- max/min bounds.
|
||||
@ -850,8 +851,8 @@ gbracketIO bef exc aft (Unfold estep einject) (Unfold step1 inject1) =
|
||||
--
|
||||
{-# INLINE_NORMAL _before #-}
|
||||
_before :: Monad m => (a -> m c) -> Unfold m a b -> Unfold m a b
|
||||
_before action unf = gbracket (\x -> action x >> return x) (fmap Right)
|
||||
(\_ -> return ()) undefined unf
|
||||
_before action = gbracket (\x -> action x >> return x) (fmap Right)
|
||||
(\_ -> return ()) undefined
|
||||
|
||||
-- | Run a side effect before the unfold yields its first element.
|
||||
--
|
||||
@ -864,8 +865,7 @@ before action (Unfold step1 inject1) = Unfold step inject
|
||||
|
||||
inject x = do
|
||||
_ <- action x
|
||||
st <- inject1 x
|
||||
return st
|
||||
inject1 x
|
||||
|
||||
{-# INLINE_LATE step #-}
|
||||
step st = do
|
||||
@ -932,10 +932,10 @@ afterIO action (Unfold step1 inject1) = Unfold step inject
|
||||
|
||||
{-# INLINE_NORMAL _onException #-}
|
||||
_onException :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
|
||||
_onException action unf =
|
||||
_onException action =
|
||||
gbracket return MC.try
|
||||
(\_ -> return ())
|
||||
(nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
|
||||
(nilM (\(a, e :: MC.SomeException) -> action a >> MC.throwM e))
|
||||
|
||||
-- | Run a side effect whenever the unfold aborts due to an exception.
|
||||
--
|
||||
@ -960,9 +960,9 @@ onException action (Unfold step1 inject1) = Unfold step inject
|
||||
|
||||
{-# INLINE_NORMAL _finally #-}
|
||||
_finally :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
|
||||
_finally action unf =
|
||||
_finally action =
|
||||
gbracket return MC.try action
|
||||
(nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
|
||||
(nilM (\(a, e :: MC.SomeException) -> action a >> MC.throwM e))
|
||||
|
||||
-- | Run a side effect whenever the unfold stops normally or aborts due to an
|
||||
-- exception.
|
||||
@ -1019,9 +1019,9 @@ finallyIO action (Unfold step1 inject1) = Unfold step inject
|
||||
{-# INLINE_NORMAL _bracket #-}
|
||||
_bracket :: MonadCatch m
|
||||
=> (a -> m c) -> (c -> m d) -> Unfold m c b -> Unfold m a b
|
||||
_bracket bef aft unf =
|
||||
gbracket bef MC.try aft (nilM (\(a, (e :: MC.SomeException)) -> aft a >>
|
||||
MC.throwM e)) unf
|
||||
_bracket bef aft =
|
||||
gbracket bef MC.try aft (nilM (\(a, e :: MC.SomeException) -> aft a >>
|
||||
MC.throwM e))
|
||||
|
||||
-- | @bracket before after between@ runs the @before@ action and then unfolds
|
||||
-- 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
|
||||
{-# INLINE_NORMAL handle #-}
|
||||
handle :: (MonadCatch m, Exception e)
|
||||
=> Unfold m e b -> Unfold m a b -> Unfold m a b
|
||||
handle exc unf =
|
||||
gbracket return MC.try (\_ -> return ()) (discardFirst exc) unf
|
||||
handle exc =
|
||||
gbracket return MC.try (\_ -> return ()) (discardFirst exc)
|
||||
|
@ -157,6 +157,7 @@ decodeTable = [
|
||||
12,36,12,12,12,12,12,12,12,12,12,12
|
||||
]
|
||||
|
||||
{-# NOINLINE utf8d #-}
|
||||
utf8d :: A.Array Word8
|
||||
utf8d =
|
||||
unsafePerformIO
|
||||
@ -180,7 +181,7 @@ unsafePeekElemOff p i = let !x = A.unsafeInlineIO $ peekElemOff p i in x
|
||||
decode0 :: Ptr Word8 -> Word8 -> Tuple' DecodeState CodePoint
|
||||
decode0 table byte =
|
||||
let !t = table `unsafePeekElemOff` fromIntegral byte
|
||||
!codep' = (0xff `shiftR` (fromIntegral t)) .&. fromIntegral byte
|
||||
!codep' = (0xff `shiftR` fromIntegral t) .&. fromIntegral byte
|
||||
!state' = table `unsafePeekElemOff` (256 + fromIntegral t)
|
||||
in assert ((byte > 0x7f || error showByte)
|
||||
&& (state' /= 0 || error (showByte ++ showTable)))
|
||||
@ -246,7 +247,7 @@ data FreshPoint s a
|
||||
decodeUtf8WithD :: Monad m => CodingFailureMode -> Stream m Word8 -> Stream m Char
|
||||
decodeUtf8WithD cfm (Stream step state) =
|
||||
let A.Array p _ _ = utf8d
|
||||
!ptr = (unsafeForeignPtrToPtr p)
|
||||
!ptr = unsafeForeignPtrToPtr p
|
||||
in Stream (step' ptr) (FreshPointDecodeInit state)
|
||||
where
|
||||
{-# INLINE transliterateOrError #-}
|
||||
@ -337,7 +338,7 @@ resumeDecodeUtf8EitherD
|
||||
-> Stream m (Either DecodeError Char)
|
||||
resumeDecodeUtf8EitherD dst codep (Stream step state) =
|
||||
let A.Array p _ _ = utf8d
|
||||
!ptr = (unsafeForeignPtrToPtr p)
|
||||
!ptr = unsafeForeignPtrToPtr p
|
||||
stt =
|
||||
if dst == 0
|
||||
then FreshPointDecodeInit state
|
||||
@ -431,7 +432,7 @@ decodeUtf8ArraysWithD ::
|
||||
-> Stream m Char
|
||||
decodeUtf8ArraysWithD cfm (Stream step state) =
|
||||
let A.Array p _ _ = utf8d
|
||||
!ptr = (unsafeForeignPtrToPtr p)
|
||||
!ptr = unsafeForeignPtrToPtr p
|
||||
in Stream (step' ptr) (OuterLoop state Nothing)
|
||||
where
|
||||
{-# INLINE transliterateOrError #-}
|
||||
|
@ -67,7 +67,7 @@ import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
|
||||
import Control.Exception (onException)
|
||||
import Control.Monad.Catch (MonadCatch, finally, MonadMask)
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Control.Monad (when)
|
||||
import Control.Monad (forM_, when)
|
||||
import Data.Word (Word8)
|
||||
import Foreign.ForeignPtr (withForeignPtr)
|
||||
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
|
||||
@ -164,7 +164,7 @@ listenTuples = Unfold step inject
|
||||
liftIO $ initListener listenQLen spec addr
|
||||
|
||||
step listener = do
|
||||
r <- liftIO $ (Net.accept listener `onException` Net.close listener)
|
||||
r <- liftIO (Net.accept listener `onException` Net.close listener)
|
||||
return $ D.Yield r listener
|
||||
|
||||
-- | Unfold a three tuple @(listenQLen, spec, addr)@ into a stream of connected
|
||||
@ -189,9 +189,7 @@ connectCommon SockSpec{..} local remote = withSocketsDo $ do
|
||||
|
||||
use sock = do
|
||||
mapM_ (\(opt, val) -> setSocketOption sock opt val) sockOpts
|
||||
case local of
|
||||
Nothing -> return ()
|
||||
Just addr -> bind sock addr
|
||||
forM_ local (bind sock)
|
||||
Net.connect sock remote
|
||||
|
||||
-- | Connect to a remote host using the given socket specification and remote
|
||||
@ -201,7 +199,7 @@ connectCommon SockSpec{..} local remote = withSocketsDo $ do
|
||||
--
|
||||
{-# INLINE connect #-}
|
||||
connect :: SockSpec -> SockAddr -> IO Socket
|
||||
connect spec remote = connectCommon spec Nothing remote
|
||||
connect spec = connectCommon spec Nothing
|
||||
|
||||
-- | Connect to a remote host using the given socket specification, a local
|
||||
-- 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
|
||||
--
|
||||
{-# INLINE connectFrom #-}
|
||||
connectFrom :: SockSpec -> SockAddr -> SockAddr -> IO Socket
|
||||
connectFrom spec local remote = connectCommon spec (Just local) remote
|
||||
connectFrom spec local = connectCommon spec (Just local)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Listen (Streams)
|
||||
@ -224,11 +222,11 @@ recvConnectionTuplesWith tcpListenQ spec addr = S.unfoldrM step Nothing
|
||||
where
|
||||
step Nothing = do
|
||||
listener <- liftIO $ initListener tcpListenQ spec addr
|
||||
r <- liftIO $ (Net.accept listener `onException` Net.close listener)
|
||||
r <- liftIO (Net.accept listener `onException` Net.close listener)
|
||||
return $ Just (r, Just listener)
|
||||
|
||||
step (Just listener) = do
|
||||
r <- liftIO $ (Net.accept listener `onException` Net.close listener)
|
||||
r <- liftIO (Net.accept listener `onException` Net.close listener)
|
||||
return $ Just (r, Just listener)
|
||||
|
||||
-- | Start a TCP stream server that listens for connections on the supplied
|
||||
|
Loading…
Reference in New Issue
Block a user