Skip to content

Commit bbbbd5a

Browse files
authored
Merge pull request #11789 from cabalism/hlint/use-map-once
HLint: map once & with tuple-section
2 parents 44b3b66 + 73cd121 commit bbbbd5a

8 files changed

Lines changed: 16 additions & 19 deletions

File tree

.hlint.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
- ignore: {name: "Use fold"} # 1 hint
2828
- ignore: {name: "Use fst"} # 2 hints
2929
- ignore: {name: "Use lambda-case"} # 58 hints
30-
- ignore: {name: "Use map once"} # 6 hints
31-
- ignore: {name: "Use map with tuple-section"} # 3 hints
3230
- ignore: {name: "Use newtype instead of data"} # 31 hints
3331
- ignore: {name: "Use null"} # 2 hints
3432
- ignore: {name: "Use record patterns"} # 16 hints

Cabal/src/Distribution/Simple/SrcDist.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE FlexibleContexts #-}
33
{-# LANGUAGE RankNTypes #-}
4+
{-# LANGUAGE TupleSections #-}
45

56
-----------------------------------------------------------------------------
67

@@ -311,7 +312,7 @@ prepareTree
311312
-> IO ()
312313
prepareTree verbosity mbWorkDir pkg_descr0 targetDir pps = do
313314
ordinary <- listPackageSources verbosity mbWorkDir pkg_descr pps
314-
installOrdinaryFiles verbosity targetDir (zip (repeat []) $ map i ordinary)
315+
installOrdinaryFiles verbosity targetDir (map (([],) . i) ordinary)
315316
maybeCreateDefaultSetupScript targetDir
316317
where
317318
i = interpretSymbolicPath mbWorkDir -- See Note [Symbolic paths] in Distribution.Utils.Path

Cabal/src/Distribution/Simple/Test.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE FlexibleContexts #-}
44
{-# LANGUAGE NamedFieldPuns #-}
55
{-# LANGUAGE RankNTypes #-}
6+
{-# LANGUAGE TupleSections #-}
67
{-# LANGUAGE ViewPatterns #-}
78

89
-----------------------------------------------------------------------------
@@ -132,7 +133,7 @@ test args verbHandles pkg_descr lbi0 flags = do
132133
dieWithException verbosity NoTestSuitesEnabled
133134

134135
testsToRun <- case testNames of
135-
[] -> return $ zip enabledTests $ repeat Nothing
136+
[] -> return $ map (,Nothing) enabledTests
136137
names -> for names $ \tName ->
137138
let testMap = zip enabledNames enabledTests
138139
enabledNames = map (PD.testName . fst) enabledTests

Cabal/src/Distribution/Simple/UHC.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
231231
-- source files
232232
-- suboptimal: UHC does not understand module names, so
233233
-- we replace periods by path separators
234-
++ map
235-
(map (\c -> if c == '.' then pathSeparator else c))
236-
(map prettyShow (allLibModules lib clbi))
234+
++ map (map (\c -> if c == '.' then pathSeparator else c) . prettyShow) (allLibModules lib clbi)
237235

238236
runUhcProg uhcArgs
239237

cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,16 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do
8282
. filter (either (const True) (not . null))
8383
-- Try decoding strictly; if it fails, put the lenient
8484
-- decoding in a Left for later reporting.
85-
. map (\bsname ->
86-
let sbsname = LBS.toStrict bsname
87-
in case T.decodeUtf8' sbsname of
88-
Left _ -> Left (T.unpack (decodeUtf8LenientCompat sbsname))
89-
Right name -> Right (T.unpack name))
9085
-- The output of @pkg-config --list-all@ also includes a
9186
-- description for each package, which we do not need.
9287
-- We don't use Data.Char.isSpace because that would also
9388
-- include 0xA0, the non-breaking space, which can occur
9489
-- in multi-byte UTF-8 sequences.
95-
. map (LBS.takeWhile (not . isAsciiSpace))
90+
. map ((\bsname ->
91+
let sbsname = LBS.toStrict bsname
92+
in case T.decodeUtf8' sbsname of
93+
Left _ -> Left (T.unpack (decodeUtf8LenientCompat sbsname))
94+
Right name -> Right (T.unpack name)) . LBS.takeWhile (not . isAsciiSpace))
9695
$ pkgList
9796
unless (null failedPkgNames) $
9897
info verbosity ("Some pkg-config packages have names containing invalid unicode: " ++ intercalate ", " failedPkgNames)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
192192
J.object $
193193
[ comp2str c
194194
J..= J.object
195-
( [ "depends" J..= map (jdisplay . confInstId) (map fst ldeps)
195+
( [ "depends" J..= map ((jdisplay . confInstId) . fst) ldeps
196196
, "exe-depends" J..= map (jdisplay . confInstId) edeps
197197
]
198198
++ bin_file c
@@ -205,7 +205,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
205205
]
206206
in ["components" J..= components]
207207
ElabComponent comp ->
208-
[ "depends" J..= map (jdisplay . confInstId) (map fst $ elabLibDependencies elab)
208+
[ "depends" J..= map ((jdisplay . confInstId) . fst) (elabLibDependencies elab)
209209
, "exe-depends" J..= map jdisplay (elabExeDependencies elab)
210210
, "component-name" J..= J.String (comp2str (compSolverName comp))
211211
]
@@ -640,7 +640,7 @@ postBuildProjectStatus
640640
]
641641

642642
elabLibDeps :: ElaboratedConfiguredPackage -> [UnitId]
643-
elabLibDeps = map (newSimpleUnitId . confInstId) . map fst . elabLibDependencies
643+
elabLibDeps = map ((newSimpleUnitId . confInstId) . fst) . elabLibDependencies
644644

645645
-- Was a build was attempted for this package?
646646
-- If it doesn't have both a build status and outcome then the answer is no.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,8 +3305,7 @@ nubComponentTargets =
33053305
concatMap (wholeComponentOverrides . map snd)
33063306
. groupBy ((==) `on` fst)
33073307
. sortBy (compare `on` fst)
3308-
. map (\t@((ComponentTarget cname _, _)) -> (cname, t))
3309-
. map compatSubComponentTargets
3308+
. map ((\t@((ComponentTarget cname _, _)) -> (cname, t)) . compatSubComponentTargets)
33103309
where
33113310
-- If we're building the whole component then that the only target all we
33123311
-- need, otherwise we can have several targets within the component.

cabal-install/tests/UnitTests/Distribution/Client/InstallPlan.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE ConstraintKinds #-}
2+
{-# LANGUAGE TupleSections #-}
23
{-# LANGUAGE TypeFamilies #-}
34
{-# LANGUAGE NoMonoLocalBinds #-}
45

@@ -136,7 +137,7 @@ isReversePartialTopologicalOrder g vs =
136137
| let ixs =
137138
array
138139
(bounds g)
139-
( zip (range (bounds g)) (repeat Nothing)
140+
( map (,Nothing) (range (bounds g))
140141
++ zip vs (map Just [0 :: Int ..])
141142
)
142143
, (u, v) <- edges g

0 commit comments

Comments
 (0)