[GHC] #12044: Remove sortWith in favor of sortOn

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: | Version: 7.10.3 libraries/base | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Other Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: 2659 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- There is Data.List.sortOn that does the same as GHC.Exts.sortWith, and even seems to be more effective. GHC.Exts.sortWith should be deprecated or removed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * keywords: => newcomer * related: 2659 => #2659 Comment: Sure. Do something like this: * add a `DEPRECATED` pragma to `sortWith` * add an entry in the base release notes (`libraries/base/changelog.md`) that `sortWith` is deprecated * replace use of `sortWith` in the compiler, libraries, and testsuite by `sortOn` * replace the implementation of `sortWith` by a call to `sortOn` (optional) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): I don't understand what the "for good reasons" means in the following [https://mail.haskell.org/pipermail/libraries/2014-April/022502.html comment]:
that name just reminded me of GHC.Exts.sortWith: http://hackage.haskell.org/package/base-4.6.0.1/docs/GHC- Exts.html#v:sortWith
Which actually has the right type signature, but it's still implemented as compare (f x) (f y), and for good reasons too in this case.
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: vkonton Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vkonton): * owner: => vkonton -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: vkonton Type: feature request | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Phab:D2587 Wiki Page: | -------------------------------------+------------------------------------- Changes (by cblp): * status: new => patch * differential: => Phab:D2587 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: cblp Type: feature request | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Phab:D2587 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * owner: vkonton => cblp Comment: It's really not clear to me that this is actually a refactoring that we would want to undertake. While `sortOn` and `sortWith` are semantically equivalent, they are operationally much different. Namely, for "cheap" mapping functions (e.g. projections like `fst`) `sortOn` will allocate significantly more than `sortWith`. Consider the case of, {{{#!hs x :: [(Int, String)] x = ... by = sortBy (comparing fst) x on = sortOn fst }}} The evaluation of `on` will allocate a list of type `[(Int, (Int, String))]`, `sortBy (comparing fst)` that intermediate list, and then project back to a `[(Int, String)]`. It seems to me like this would be quite undesirable. While we may not want to deprecate `GHC.Exts.sortWith` in favor of `sortOn` in particular, perhaps we want to deprecate it nevertheless. The more standard form `sortBy (comparing f)` is only a bit longer and arguably you should be forced to consider whether or not you want to use `sortOn` instead. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: cblp Type: feature request | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Phab:D2587 Wiki Page: | -------------------------------------+------------------------------------- Comment (by cblp): Somebody should investigate and document when one should use `sortOn` or `sortWith`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12044: Remove sortWith in favor of sortOn -------------------------------------+------------------------------------- Reporter: cblp | Owner: cblp Type: feature request | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #2659 | Differential Rev(s): Phab:D2587 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari):
Somebody should investigate and document when one should use `sortOn` or `sortWith`.
In general if the mapping function is expensive to compute then you should probably be using `sortOn`, as it only needs to compute it once for each element. `sortWith`, on the other hand must compute the mapping function for every comparison that it performs. Beyond that general intuition it's hard to give any specific prescription. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12044#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC