[Git][ghc/ghc][wip/text-2.1.1] 3 commits: feat: Add sortOn to Data.List.NonEmpty

Bodigrim (@Bodigrim) gitlab at gitlab.haskell.org
Thu Feb 15 22:53:15 UTC 2024



Bodigrim pushed to branch wip/text-2.1.1 at Glasgow Haskell Compiler / GHC


Commits:
264a4fa9 by Owen Shepherd at 2024-02-15T09:41:06-05:00
feat: Add sortOn to Data.List.NonEmpty

Adds `sortOn` to `Data.List.NonEmpty`, and adds
comments describing when to use it, compared to
`sortWith` or `sortBy . comparing`.

The aim is to smooth out the API between
`Data.List`, and `Data.List.NonEmpty`.

This change has been discussed in the
[clc issue](https://github.com/haskell/core-libraries-committee/issues/227).

- - - - -
b57200de by Fendor at 2024-02-15T09:41:47-05:00
Prefer RdrName over OccName for looking up locations in doc renaming step

Looking up by OccName only does not take into account when functions are
only imported in a qualified way.

Fixes issue #24294

Bump haddock submodule to include regression test

- - - - -
7ce4b298 by Andrew Lelechenko at 2024-02-15T21:14:08+00:00
Bump submodule text to 2.1.1

T17123 allocates less because of improvements to Data.Text.concat in 1a6a06a.

Metric Decrease:
    T17123

- - - - -


10 changed files:

- compiler/GHC/Rename/Doc.hs
- libraries/base/changelog.md
- libraries/base/src/Data/List/NonEmpty.hs
- libraries/ghc-internal/src/Data/OldList.hs
- libraries/text
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/base-exports.stdout-ws-32
- utils/haddock


Changes:

=====================================
compiler/GHC/Rename/Doc.hs
=====================================
@@ -40,5 +40,5 @@ rnHsDocIdentifiers :: GlobalRdrEnv
 rnHsDocIdentifiers gre_env ns =
   [ L l $ greName gre
   | L l rdr_name <- ns
-  , gre <- lookupGRE gre_env (LookupOccName (rdrNameOcc rdr_name) AllRelevantGREs)
+  , gre <- lookupGRE gre_env (LookupRdrName rdr_name AllRelevantGREs)
   ]


=====================================
libraries/base/changelog.md
=====================================
@@ -33,6 +33,8 @@
     then the constraint `DataToTag t` can always be solved.
 
     ([CLC proposal #104](https://github.com/haskell/core-libraries-committee/issues/104))
+  * Add `sortOn` to `Data.List.NonEmpty`
+    ([CLC proposal #227](https://github.com/haskell/core-libraries-committee/issues/227))
 
   * Add more instances for `Compose`: `Fractional`, `RealFrac`, `Floating`, `RealFloat` ([CLC proposal #226](https://github.com/haskell/core-libraries-committee/issues/226))
 


=====================================
libraries/base/src/Data/List/NonEmpty.hs
=====================================
@@ -45,6 +45,7 @@ module Data.List.NonEmpty (
    , uncons      -- :: NonEmpty a -> (a, Maybe (NonEmpty a))
    , unfoldr     -- :: (a -> (b, Maybe a)) -> a -> NonEmpty b
    , sort        -- :: Ord a => NonEmpty a -> NonEmpty a
+   , sortOn      -- :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
    , reverse     -- :: NonEmpty a -> NonEmpty a
    , inits       -- :: Foldable f => f a -> NonEmpty [a]
    , inits1      -- :: NonEmpty a -> NonEmpty (NonEmpty a)
@@ -196,6 +197,39 @@ cons = (<|)
 sort :: Ord a => NonEmpty a -> NonEmpty a
 sort = lift List.sort
 
+-- | Sort a 'NonEmpty' on a user-supplied projection of its elements.
+-- See 'List.sortOn' for more detailed information.
+--
+-- ==== __Examples__
+--
+-- >>> sortOn fst $ (2, "world") :| [(4, "!"), (1, "Hello")]
+-- (1,"Hello") :| [(2,"world"),(4,"!")]
+--
+-- >>> sortOn length $ "jim" :| ["creed", "pam", "michael", "dwight", "kevin"]
+-- "jim" :| ["pam","creed","kevin","dwight","michael"]
+--
+-- ==== __Performance notes__
+--
+-- This function minimises the projections performed, by materialising
+-- the projections in an intermediate list.
+--
+-- For trivial projections, you should prefer using 'sortBy' with
+-- 'comparing', for example:
+--
+-- >>> sortBy (comparing fst) $ (3, 1) :| [(2, 2), (1, 3)]
+-- (1,3) :| [(2,2),(3,1)]
+--
+-- Or, for the exact same API as 'sortOn', you can use `sortBy . comparing`:
+--
+-- >>> (sortBy . comparing) fst $ (3, 1) :| [(2, 2), (1, 3)]
+-- (1,3) :| [(2,2),(3,1)]
+--
+-- 'sortWith' is an alias for `sortBy . comparing`.
+--
+-- @since 4.20.0.0
+sortOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
+sortOn f = lift (List.sortOn f)
+
 -- | Converts a normal list to a 'NonEmpty' stream.
 --
 -- Raises an error if given an empty list.


=====================================
libraries/ghc-internal/src/Data/OldList.hs
=====================================
@@ -1798,6 +1798,22 @@ rqpart cmp x (y:ys) rle rgt r =
 -- >>> sortOn length ["jim", "creed", "pam", "michael", "dwight", "kevin"]
 -- ["jim","pam","creed","kevin","dwight","michael"]
 --
+-- ==== __Performance notes__
+--
+-- This function minimises the projections performed, by materialising
+-- the projections in an intermediate list.
+--
+-- For trivial projections, you should prefer using 'sortBy' with
+-- 'comparing', for example:
+--
+-- >>> sortBy (comparing fst) [(3, 1), (2, 2), (1, 3)]
+-- [(1,3),(2,2),(3,1)]
+--
+-- Or, for the exact same API as 'sortOn', you can use `sortBy . comparing`:
+--
+-- >>> (sortBy . comparing) fst [(3, 1), (2, 2), (1, 3)]
+-- [(1,3),(2,2),(3,1)]
+--
 -- @since 4.8.0.0
 sortOn :: Ord b => (a -> b) -> [a] -> [a]
 sortOn f =


=====================================
libraries/text
=====================================
@@ -1 +1 @@
-Subproject commit 73620de89d43ee50de2d15b7bc0843bf6d6e9b9a
+Subproject commit 0083e7d32e2d203ce88457e62e8a282dc9f21dfb


=====================================
testsuite/tests/interface-stability/base-exports.stdout
=====================================
@@ -1423,6 +1423,7 @@ module Data.List.NonEmpty where
   some1 :: forall (f :: * -> *) a. GHC.Base.Alternative f => f a -> f (NonEmpty a)
   sort :: forall a. GHC.Classes.Ord a => NonEmpty a -> NonEmpty a
   sortBy :: forall a. (a -> a -> GHC.Types.Ordering) -> NonEmpty a -> NonEmpty a
+  sortOn :: forall b a. GHC.Classes.Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
   sortWith :: forall o a. GHC.Classes.Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
   span :: forall a. (a -> GHC.Types.Bool) -> NonEmpty a -> ([a], [a])
   splitAt :: forall a. GHC.Types.Int -> NonEmpty a -> ([a], [a])


=====================================
testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
=====================================
@@ -1423,6 +1423,7 @@ module Data.List.NonEmpty where
   some1 :: forall (f :: * -> *) a. GHC.Base.Alternative f => f a -> f (NonEmpty a)
   sort :: forall a. GHC.Classes.Ord a => NonEmpty a -> NonEmpty a
   sortBy :: forall a. (a -> a -> GHC.Types.Ordering) -> NonEmpty a -> NonEmpty a
+  sortOn :: forall b a. GHC.Classes.Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
   sortWith :: forall o a. GHC.Classes.Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
   span :: forall a. (a -> GHC.Types.Bool) -> NonEmpty a -> ([a], [a])
   splitAt :: forall a. GHC.Types.Int -> NonEmpty a -> ([a], [a])


=====================================
testsuite/tests/interface-stability/base-exports.stdout-mingw32
=====================================
@@ -1423,6 +1423,7 @@ module Data.List.NonEmpty where
   some1 :: forall (f :: * -> *) a. GHC.Base.Alternative f => f a -> f (NonEmpty a)
   sort :: forall a. GHC.Classes.Ord a => NonEmpty a -> NonEmpty a
   sortBy :: forall a. (a -> a -> GHC.Types.Ordering) -> NonEmpty a -> NonEmpty a
+  sortOn :: forall b a. GHC.Classes.Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
   sortWith :: forall o a. GHC.Classes.Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
   span :: forall a. (a -> GHC.Types.Bool) -> NonEmpty a -> ([a], [a])
   splitAt :: forall a. GHC.Types.Int -> NonEmpty a -> ([a], [a])


=====================================
testsuite/tests/interface-stability/base-exports.stdout-ws-32
=====================================
@@ -1423,6 +1423,7 @@ module Data.List.NonEmpty where
   some1 :: forall (f :: * -> *) a. GHC.Base.Alternative f => f a -> f (NonEmpty a)
   sort :: forall a. GHC.Classes.Ord a => NonEmpty a -> NonEmpty a
   sortBy :: forall a. (a -> a -> GHC.Types.Ordering) -> NonEmpty a -> NonEmpty a
+  sortOn :: forall b a. GHC.Classes.Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
   sortWith :: forall o a. GHC.Classes.Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
   span :: forall a. (a -> GHC.Types.Bool) -> NonEmpty a -> ([a], [a])
   splitAt :: forall a. GHC.Types.Int -> NonEmpty a -> ([a], [a])


=====================================
utils/haddock
=====================================
@@ -1 +1 @@
-Subproject commit 65453a58185726aab95289c2da0d9fb27b7ce0af
+Subproject commit 9fcf5cf499102baf9e00986bb8b54b80ec5ffc81



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a9534da580235f5fbf049e77448655174ca6eb48...7ce4b2986ed3380837bcd41f70374ac9c6e9993b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a9534da580235f5fbf049e77448655174ca6eb48...7ce4b2986ed3380837bcd41f70374ac9c6e9993b
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240215/f7a66111/attachment-0001.html>


More information about the ghc-commits mailing list