Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • libraries/base/changelog.md
    ... ... @@ -3,6 +3,7 @@
    3 3
     ## 4.23.0.0 *TBA*
    
    4 4
       * Add `Data.List.NonEmpty.mapMaybe`. ([CLC proposal #337](https://github.com/haskell/core-libraries-committee/issues/337))
    
    5 5
       * Fix issues with toRational for types capable to represent infinite and not-a-number values ([CLC proposal #338](https://github.com/haskell/core-libraries-committee/issues/338))
    
    6
    +  * Modify the implementation of `Data.List.sortOn` to use `(>)` instead of `compare`. ([CLC proposal #332](https://github.com/haskell/core-libraries-committee/issues/332))
    
    6 7
     
    
    7 8
     ## 4.22.0.0 *TBA*
    
    8 9
       * Shipped with GHC 9.14.1
    

  • libraries/base/src/Data/List/NonEmpty.hs
    ... ... @@ -268,6 +268,9 @@ sort = lift List.sort
    268 268
     -- >>> (sortBy . comparing) fst $ (3, 1) :| [(2, 2), (1, 3)]
    
    269 269
     -- (1,3) :| [(2,2),(3,1)]
    
    270 270
     --
    
    271
    +-- However, 'sortOn' may still be faster for instances with a more efficient
    
    272
    +-- implementation of '(>)' than 'compare'.
    
    273
    +--
    
    271 274
     -- 'sortWith' is an alias for `sortBy . comparing`.
    
    272 275
     --
    
    273 276
     -- @since 4.20.0.0
    

  • libraries/ghc-internal/src/GHC/Internal/Data/OldList.hs
    ... ... @@ -216,7 +216,6 @@ module GHC.Internal.Data.OldList
    216 216
     import GHC.Internal.Data.Maybe
    
    217 217
     import GHC.Internal.Data.Bits        ( (.&.) )
    
    218 218
     import GHC.Internal.Unicode      ( isSpace )
    
    219
    -import GHC.Internal.Data.Ord         ( comparing )
    
    220 219
     import GHC.Internal.Data.Tuple       ( fst, snd )
    
    221 220
     
    
    222 221
     import GHC.Internal.Num
    
    ... ... @@ -1862,10 +1861,13 @@ rqpart cmp x (y:ys) rle rgt r =
    1862 1861
     -- >>> (sortBy . comparing) fst [(3, 1), (2, 2), (1, 3)]
    
    1863 1862
     -- [(1,3),(2,2),(3,1)]
    
    1864 1863
     --
    
    1864
    +-- However, 'sortOn' may still be faster for instances with a more efficient
    
    1865
    +-- implementation of '(>)' than 'compare'.
    
    1866
    +--
    
    1865 1867
     -- @since base-4.8.0.0
    
    1866 1868
     sortOn :: Ord b => (a -> b) -> [a] -> [a]
    
    1867 1869
     sortOn f =
    
    1868
    -  map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))
    
    1870
    +  map snd . actualSort (\x y -> fst x > fst y) . map (\x -> let y = f x in y `seq` (y, x))
    
    1869 1871
     
    
    1870 1872
     -- | Construct a list from a single element.
    
    1871 1873
     --