Skip to content

Commit

Permalink
Merge pull request #8608 from Bodigrim/avoid-head-and-tail
Browse files Browse the repository at this point in the history
Avoid `Data.List.{head,tail}`
  • Loading branch information
mergify[bot] authored Nov 20, 2022
2 parents 050c3c5 + 60c2c91 commit 6cd2978
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 3 additions & 4 deletions Cabal-syntax/src/Language/Haskell/Extension.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module Language.Haskell.Extension (
knownExtensions
) where

import qualified Prelude (head)
import Distribution.Compat.Prelude

import Data.Array (Array, accumArray, bounds, Ix(inRange), (!))
Expand Down Expand Up @@ -752,9 +751,9 @@ classifyKnownExtension string@(c : _)
knownExtensionTable :: Array Char [(String, KnownExtension)]
knownExtensionTable =
accumArray (flip (:)) [] ('A', 'Z')
[ (Prelude.head str, (str, extension)) -- assume KnownExtension's Show returns a non-empty string
| extension <- [toEnum 0 ..]
, let str = show extension ]
[ (hd, (str, extension)) -- assume KnownExtension's Show returns a non-empty string
| (extension, str@(hd : _)) <- map (\e -> (e, show e)) [toEnum 0 ..]
]

knownExtensions :: [KnownExtension]
knownExtensions = [minBound .. maxBound]
7 changes: 4 additions & 3 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Distribution.Simple.Configure
, platformDefines,
) where

import qualified Prelude as Unsafe (tail)
import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Compiler
Expand Down Expand Up @@ -106,7 +106,8 @@ import Data.ByteString.Lazy ( ByteString )
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy.Char8 as BLC8
import Data.List
( (\\), inits, stripPrefix, intersect)
( (\\), stripPrefix, intersect)
import qualified Data.List.NonEmpty as NEL
import qualified Data.Map as Map
import System.Directory
( canonicalizePath, createDirectoryIfMissing, doesFileExist
Expand Down Expand Up @@ -1784,7 +1785,7 @@ checkForeignDeps pkg lbi verbosity =
findOffendingHdr =
ifBuildsWith allHeaders ccArgs
(return Nothing)
(go . Unsafe.tail . inits $ allHeaders) -- inits always contains at least []
(go . tail . NEL.inits $ allHeaders)
where
go [] = return Nothing -- cannot happen
go (hdrs:hdrsInits) =
Expand Down

0 comments on commit 6cd2978

Please sign in to comment.