[GHC] #9330: Introduce shortcut for "on (==)" much like there's a shortcut for "on compare".

#9330: Introduce shortcut for "on (==)" much like there's a shortcut for "on compare". -------------------------------------+------------------------------------- Reporter: frerich | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.8.2 Keywords: | Differential Revisions: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: -------------------------------------+------------------------------------- A common use case for `on` (from `Data.Function`) is to use it with `compare`, e.g. {{{compare `on` snd}}}. In fact, this pattern is so common that there's a convenient `comparing` function which provides a shortcut for this use case such that one can write {{{ #!haskell sortBy (comparing snd) }}} instead of {{{ #!haskell sortBy (compare `on` snd) }}} I think another common use case is to use `on` together with `(==)` as in {{{ #!haskell groupBy ((==) `on` snd) }}} In a similiar vein as with `comparing`, I think it would be nice if there was a function which encapsulates this use case, like {{{ #!haskell equating :: Eq b => (a -> b) -> a -> a -> Bool equating = on (==) }}} such that one can write {{{ #!haskell groupBy (equating snd) }}} The (IMHO fairly nice) name `equating` is not my idea but was suggested by //ClaudiusMaximus// of #haskell fame. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9330 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9330: Introduce shortcut for "on (==)" much like there's a shortcut for "on compare". -------------------------------------+------------------------------------- Reporter: frerich | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.2 Component: | Keywords: libraries/base | Operating System: Unknown/Multiple Resolution: | Type of failure: None/Unknown Differential Revisions: | Test Case: Architecture: | Blocking: Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: | -------------------------------------+------------------------------------- Comment (by frerich): A lot of `*By` functions taking an `a -> a -> Bool` are in `Data.List`, e.g. `groupBy`, `nubBy`, `deleteBy`, `intersectBy`, `unionBy`. Hence, it seems plausible to define `equating` in `Data.List`. This is the same reasoning as why `comparing` is in `Data.Ord`: because the module exposes a lot of `*By` functions taking an `a -> a -> Ordering`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9330#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9330: Introduce shortcut for "on (==)" much like there's a shortcut for "on compare". -------------------------------------+------------------------------------- Reporter: frerich | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.2 Component: | Keywords: libraries/base | Operating System: Unknown/Multiple Resolution: | Type of failure: None/Unknown Differential Revisions: | Test Case: Architecture: | Blocking: Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: | -------------------------------------+------------------------------------- Comment (by ekmett): A couple of items: Historically, `comparing` was actually defined before `on` was added to `base`. Fear that we'd be duplicating that pattern over and over again for every other function under the sun led to the adoption of `on`. `equating` was explicitly the original motivation! `comparing` was left in because it was already there, but not _really_ intended to be a pattern to copy, `on` was the general solution put forth to avoid precisely this repetition. The main reason why we should consider doing this is, well, frankly, it gets reinvented every 6 months, so by not doing it we seem to be on the wrong side of history. Eventually someone will say yes. ;) That said, library changes like this should go through a libraries@haskell.org request, rather than trac. Please submit this as a libraries@ mailing list proposal, that'll garner general sentiment and the core libraries committee can weigh in there. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9330#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9330: Introduce shortcut for "on (==)" much like there's a shortcut for "on compare". -------------------------------------+------------------------------------- Reporter: frerich | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.8.2 Component: | Keywords: libraries/base | Operating System: Unknown/Multiple Resolution: | Type of failure: None/Unknown Differential Revisions: | Test Case: Architecture: | Blocking: Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: | -------------------------------------+------------------------------------- Comment (by hvr): Fairbairn-threshold, anyone? :) {{{#!hs
length "equating" > length "on (==)" True }}}
(fwiw, I would rather see `on` being exported by `Prelude` than add `equating` to `Data.Eq`) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9330#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9330: Introduce shortcut for "on (==)" much like there's a shortcut for "on compare". -------------------------------------+------------------------------------- Reporter: frerich | Owner: ekmett Type: feature | Status: closed request | Milestone: Priority: normal | Version: 7.8.2 Component: Core | Keywords: Libraries | Architecture: Unknown/Multiple Resolution: wontfix | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * cc: core-libraries-committee@… (added) * status: new => closed * resolution: => wontfix Comment: Here's a link to the library submission. The discussion never reached a conclusion, as far as I can tell: https://www.haskell.org/pipermail/libraries/2014-July/023283.html Please reopen if this proposal ever gets accepted in the future. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9330#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC