[GHC] #9241: Add a"same" function to Data.Eq

GHC ghc-devs at haskell.org
Thu Jun 26 14:05:22 UTC 2014


#9241: Add a"same" function to Data.Eq
-------------------------------------+------------------------------------
        Reporter:  mhwombat          |            Owner:
            Type:  feature request   |           Status:  new
        Priority:  low               |        Milestone:
       Component:  libraries/base    |          Version:  7.8.2
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------
Changes (by hvr):

 * cc: hvr, ekmett (added)
 * component:  Prelude => libraries/base


Old description:

> Add a"same" function to Data.Eq that parallels the "comparing" function
> in Data.Ord. For example:
>
> -- |
> -- > same p x y = (p x) == (p y)
> --
> -- Useful combinator for use in conjunction with the @xxxBy@ family
> -- of functions from "Data.List", for example:
> --
> -- >   ... groupBy (same fst) ...
> same :: (Eq a) => (b -> a) -> b -> b -> Bool
> same p x y = (p x) == (p y)
>
> For a closer parallel, I suppose "same" could return "Equality" (similar
> to "Ordering"), and the functions "nubBy", "deleteBy", "deleteFirstsBy",
> "unionBy", "intersectBy" and "groupBy" should take (a -> a -> Equality)
> (a -> a -> Bool). But I don't know if there's any benefit to that.

New description:

 Add a"same" function to Data.Eq that parallels the "comparing" function in
 Data.Ord. For example:

 {{{#!hs
 -- |
 -- > same p x y = (p x) == (p y)
 --
 -- Useful combinator for use in conjunction with the @xxxBy@ family
 -- of functions from "Data.List", for example:
 --
 -- >   ... groupBy (same fst) ...
 same :: (Eq a) => (b -> a) -> b -> b -> Bool
 same p x y = (p x) == (p y)
 }}}

 For a closer parallel, I suppose "same" could return "Equality" (similar
 to "Ordering"), and the functions "nubBy", "deleteBy", "deleteFirstsBy",
 "unionBy", "intersectBy" and "groupBy" should take (a -> a -> Equality) (a
 -> a -> Bool). But I don't know if there's any benefit to that.

--

Comment:

 What's the benefit of `same p` over {{{(==) `on` p}}}?

 {{{#!hs
 ((==) `on`) :: Eq b => (a -> b) -> a -> a -> Bool
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9241#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list