summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2022-11-24 23:15:48 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-25 04:38:28 -0500
commit1f1b99b86ab2b005604aea08b0614279a8ad1244 (patch)
tree102e0c622093933371d3e1b6c90a8277b0de2d18
parent5943e739f8060bcc9867ef048a462f2c465fde00 (diff)
downloadhaskell-1f1b99b86ab2b005604aea08b0614279a8ad1244.tar.gz
Review suggestions for assorted fixes to avoid Data.List.{head,tail}
-rw-r--r--libraries/ghc-boot/GHC/BaseDir.hs5
-rw-r--r--libraries/ghc-boot/GHC/Data/ShortText.hs9
2 files changed, 8 insertions, 6 deletions
diff --git a/libraries/ghc-boot/GHC/BaseDir.hs b/libraries/ghc-boot/GHC/BaseDir.hs
index 66ed339e32..0001837f75 100644
--- a/libraries/ghc-boot/GHC/BaseDir.hs
+++ b/libraries/ghc-boot/GHC/BaseDir.hs
@@ -16,7 +16,8 @@ module GHC.BaseDir where
import Prelude -- See Note [Why do we import Prelude here?]
-import Data.List (stripPrefix, uncons)
+import Data.List (stripPrefix)
+import Data.Maybe (listToMaybe)
import System.FilePath
-- Windows
@@ -37,7 +38,7 @@ expandTopDir = expandPathVar "topdir"
expandPathVar :: String -> FilePath -> String -> String
expandPathVar var value str
| Just str' <- stripPrefix ('$':var) str
- , maybe True (isPathSeparator . fst) (uncons str')
+ , maybe True isPathSeparator (listToMaybe str')
= value ++ expandPathVar var value str'
expandPathVar var value (x:xs) = x : expandPathVar var value xs
expandPathVar _ _ [] = []
diff --git a/libraries/ghc-boot/GHC/Data/ShortText.hs b/libraries/ghc-boot/GHC/Data/ShortText.hs
index 477d2b9a6d..9ea261435f 100644
--- a/libraries/ghc-boot/GHC/Data/ShortText.hs
+++ b/libraries/ghc-boot/GHC/Data/ShortText.hs
@@ -47,7 +47,6 @@ import Control.DeepSeq as DeepSeq
import Data.Binary
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Short.Internal as SBS
-import Data.List (uncons)
import GHC.Exts
import GHC.IO
import GHC.Utils.Encoding
@@ -101,9 +100,11 @@ splitFilePath st = DeepSeq.force $ map (ShortText . SBS.toShort) $ B8.splitWith
-- question, this may or may not be the actual first character in the string due to Unicode
-- non-printable characters.
head :: ShortText -> Char
-head st = case uncons (unpack st) of
- Nothing -> error "head: Empty ShortText"
- Just (hd, _) -> hd
+head st
+ | hd:_ <- unpack st
+ = hd
+ | otherwise
+ = error "head: Empty ShortText"
-- | /O(n)/ The 'stripPrefix' function takes two 'ShortText's and returns 'Just' the remainder of
-- the second iff the first is its prefix, and otherwise Nothing.