Skip to content

Commit bad5bc6

Browse files
authored
Merge pull request #11916 from cabalism/hlint/monadic-compose
Follow hlint suggestions to use monadic compose
2 parents 8a1058f + cc02c4d commit bad5bc6

7 files changed

Lines changed: 19 additions & 17 deletions

File tree

.hlint.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
- ignore: {name: "Use ++"} # 4 hints
1414
- ignore: {name: "Use :"} # 30 hints
1515
- ignore: {name: "Use <$>"} # 83 hints
16-
- ignore: {name: "Use <=<"} # 4 hints
1716
- ignore: {name: "Use =<<"} # 7 hints
18-
- ignore: {name: "Use >=>"} # 3 hints
1917
- ignore: {name: "Use Down"} # 3 hints
2018
- ignore: {name: "Use bimap"} # 7 hints
2119
- ignore: {name: "Use camelCase"} # 92 hints

Cabal-syntax/src/Distribution/Utils/Generic.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import Prelude ()
8787

8888
import Control.Concurrent (threadDelay)
8989
import qualified Control.Exception as Exception
90+
import Control.Monad ((>=>))
9091
import Data.Bits (shiftL, (.&.), (.|.))
9192
import qualified Data.ByteString as SBS
9293
import qualified Data.ByteString.Lazy as LBS
@@ -161,11 +162,7 @@ wrapLine width = wrap 0 []
161162
-- The file is read lazily; if it is not fully consumed by the action then an
162163
-- exception is thrown.
163164
withFileContents :: FilePath -> (String -> IO a) -> IO a
164-
withFileContents name action =
165-
withFile
166-
name
167-
ReadMode
168-
(\hnd -> hGetContents hnd >>= action)
165+
withFileContents name action = withFile name ReadMode (hGetContents >=> action)
169166

170167
-- | Writes a file atomically.
171168
--
@@ -317,7 +314,7 @@ withUTF8FileContents name action =
317314
withBinaryFile
318315
name
319316
ReadMode
320-
(\hnd -> LBS.hGetContents hnd >>= action . ignoreBOM . fromUTF8LBS)
317+
(LBS.hGetContents >=> action . ignoreBOM . fromUTF8LBS)
321318

322319
-- | Writes a Unicode String as a UTF8 encoded text file.
323320
--

cabal-dev-scripts/src/GenSPDX.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
module Main (main) where
33

44
import Control.Lens (imap)
5+
import Control.Monad ((<=<))
56
import Data.Aeson (FromJSON (..), eitherDecode, withObject, (.!=), (.:), (.:?))
67
import Data.List (sortOn)
78
import Data.Text (Text)
@@ -55,7 +56,7 @@ main = generate =<< O.execParser opts where
5556

5657
generate :: Opts -> IO ()
5758
generate (Opts tmplFile fns out) = do
58-
lss <- for fns $ \fn -> either fail pure . eitherDecode =<< LBS.readFile fn
59+
lss <- for fns (either fail pure . eitherDecode <=< LBS.readFile)
5960
template <- Z.parseAndCompileTemplateIO tmplFile
6061
output <- generate' lss template
6162
writeFile out (header <> "\n" <> output)

cabal-dev-scripts/src/GenSPDXExc.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
module Main (main) where
33

44
import Control.Lens (imap)
5+
import Control.Monad ((<=<))
56
import Data.Aeson (FromJSON (..), eitherDecode, withObject, (.:))
67
import Data.List (sortOn)
78
import Data.Text (Text)
@@ -55,7 +56,7 @@ main = generate =<< O.execParser opts where
5556

5657
generate :: Opts -> IO ()
5758
generate (Opts tmplFile fns out) = do
58-
lss <- for fns $ \fn -> either fail pure . eitherDecode =<< LBS.readFile fn
59+
lss <- for fns (either fail pure . eitherDecode <=< LBS.readFile)
5960
template <- Z.parseAndCompileTemplateIO tmplFile
6061
output <- generate' lss template
6162
writeFile out (header <> "\n" <> output)

cabal-install/src/Distribution/Client/HashValue.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Distribution.Client.HashValue
99
, hashFromTUF
1010
) where
1111

12+
import Control.Monad ((<=<))
1213
import Distribution.Client.Compat.Prelude
1314
import Prelude ()
1415

@@ -56,8 +57,7 @@ showHashValue (HashValue digest) = BS.unpack (Base16.encode digest)
5657
-- | Hash the content of a file. Uses SHA256.
5758
readFileHashValue :: FilePath -> IO HashValue
5859
readFileHashValue tarball =
59-
withBinaryFile tarball ReadMode $ \hnd ->
60-
evaluate . hashValue =<< LBS.hGetContents hnd
60+
withBinaryFile tarball ReadMode (evaluate . hashValue <=< LBS.hGetContents)
6161

6262
-- | Convert a hash from TUF metadata into a 'PackageSourceHash'.
6363
--

cabal-install/src/Distribution/Client/ProjectPlanOutput.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,10 @@ readPackagesUpToDateCacheFile :: DistDirLayout -> IO PackagesUpToDate
777777
readPackagesUpToDateCacheFile DistDirLayout{distProjectCacheFile} =
778778
handleDoesNotExist Set.empty $
779779
handleDecodeFailure $
780-
withBinaryFile (distProjectCacheFile "up-to-date") ReadMode $ \hnd ->
781-
Binary.decodeOrFailIO =<< BS.hGetContents hnd
780+
withBinaryFile
781+
(distProjectCacheFile "up-to-date")
782+
ReadMode
783+
(Binary.decodeOrFailIO <=< BS.hGetContents)
782784
where
783785
handleDecodeFailure = fmap (fromRight Set.empty)
784786

cabal-install/src/Distribution/Client/SourceFiles.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-- we cannot "see" easily.
1313
module Distribution.Client.SourceFiles (needElaboratedConfiguredPackage) where
1414

15+
import Control.Monad ((>=>))
1516
import Control.Monad.IO.Class
1617

1718
import Distribution.Client.ProjectPlanning.Types
@@ -190,9 +191,11 @@ needBuildInfo pkg_descr bi modules = do
190191
, map getSymbolicPath $ asmSources bi
191192
, map getSymbolicPath expandedExtraSrcFiles
192193
]
193-
for_ (fmap getSymbolicPath $ installIncludes bi) $ \f ->
194-
findFileMonitored ("." : fmap getSymbolicPath (includeDirs bi)) f
195-
>>= maybe (return ()) need
194+
for_
195+
(fmap getSymbolicPath $ installIncludes bi)
196+
( findFileMonitored ("." : fmap getSymbolicPath (includeDirs bi))
197+
>=> maybe (return ()) need
198+
)
196199
where
197200
findNeededModules :: [Suffix] -> Rebuild ()
198201
findNeededModules exts =

0 commit comments

Comments
 (0)