summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorBodigrim <andrew.lelechenko@gmail.com>2022-09-28 00:15:53 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-09-28 17:50:28 -0400
commit2f050687e75ffe6fbf140cacd15fd916d2997499 (patch)
treeacd68576f0210c85f69b392cb10a7048ee97d17e /ghc
parentb0c89dfaf9f8aeda9dd69a9583fd29150099aa27 (diff)
downloadhaskell-2f050687e75ffe6fbf140cacd15fd916d2997499.tar.gz
Avoid Data.List.group; prefer Data.List.NonEmpty.group
This allows to avoid further partiality, e. g., map head . group is replaced by map NE.head . NE.group, and there are less panic calls.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs7
-rw-r--r--ghc/GHCi/UI/Tags.hs10
2 files changed, 9 insertions, 8 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 99826e7144..6cbf4dffb9 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -122,8 +122,9 @@ import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Function
import Data.IORef ( IORef, modifyIORef, newIORef, readIORef, writeIORef )
-import Data.List ( elemIndices, find, group, intercalate, intersperse,
+import Data.List ( elemIndices, find, intercalate, intersperse,
isPrefixOf, isSuffixOf, nub, partition, sort, sortBy, (\\) )
+import qualified Data.List.NonEmpty as NE
import qualified Data.Set as S
import Data.Maybe
import qualified Data.Map as M
@@ -3699,11 +3700,11 @@ completeSetOptions = wrapCompleter flagWordBreakChars $ \w -> do
return (filter (w `isPrefixOf`) opts)
where opts = "args":"prog":"prompt":"prompt-cont":"prompt-function":
"prompt-cont-function":"editor":"stop":flagList
- flagList = map head $ group $ sort allNonDeprecatedFlags
+ flagList = map NE.head $ NE.group $ sort allNonDeprecatedFlags
completeSeti = wrapCompleter flagWordBreakChars $ \w -> do
return (filter (w `isPrefixOf`) flagList)
- where flagList = map head $ group $ sort allNonDeprecatedFlags
+ where flagList = map NE.head $ NE.group $ sort allNonDeprecatedFlags
completeShowOptions = wrapCompleter flagWordBreakChars $ \w -> do
return (filter (w `isPrefixOf`) opts)
diff --git a/ghc/GHCi/UI/Tags.hs b/ghc/GHCi/UI/Tags.hs
index 410b2c5927..f1d55eab15 100644
--- a/ghc/GHCi/UI/Tags.hs
+++ b/ghc/GHCi/UI/Tags.hs
@@ -29,7 +29,8 @@ import GHC.Driver.Env
import Control.Monad
import Data.Function
-import Data.List (sort, sortBy, groupBy)
+import Data.List (sort, sortOn)
+import qualified Data.List.NonEmpty as NE
import Data.Maybe
import Data.Ord
import GHC.Driver.Phases
@@ -176,14 +177,13 @@ collateAndWriteTags ETags file tagInfos = do -- etags style, Emacs/XEmacs
makeTagGroupsWithSrcInfo :: [TagInfo] -> IO [[TagInfo]]
makeTagGroupsWithSrcInfo tagInfos = do
- let groups = groupBy ((==) `on` tagFile) $ sortBy (comparing tagFile) tagInfos
+ let groups = NE.groupAllWith tagFile tagInfos
mapM addTagSrcInfo groups
where
- addTagSrcInfo [] = throwGhcException (CmdLineError "empty tag file group??")
- addTagSrcInfo group@(tagInfo:_) = do
+ addTagSrcInfo group@(tagInfo NE.:| _) = do
file <- readFile $ tagFile tagInfo
- let sortedGroup = sortBy (comparing tagLine) group
+ let sortedGroup = sortOn tagLine (NE.toList group)
return $ perFile sortedGroup 1 0 $ lines file
perFile allTags@(tag:tags) cnt pos allLs@(l:ls)