Opened 2 years ago

Closed 2 years ago

#9241 closed feature request (duplicate)

Add a"same" function to Data.Eq

Reported by: mhwombat Owned by:
Priority: low Milestone:
Component: libraries/base Version: 7.8.2
Keywords: Cc: hvr, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by hvr)

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.

Change History (4)

comment:1 Changed 2 years ago by hvr

  • Cc hvr ekmett added
  • Component changed from Prelude to libraries/base
  • Description modified (diff)

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

((==) `on`) :: Eq b => (a -> b) -> a -> a -> Bool

comment:2 Changed 2 years ago by rwbarton

Additions to base should go through the process.

Also, see #979 which suggests adding the same function under the name equating.

comment:3 Changed 2 years ago by ekmett

I agree that this should go through the libraries@ process.

For the record I'm also on the equating bandwagon, but keep in mind comparing was created before on was discovered, so when this has come up for discussion before comparing was being left around as a historical artifact than as a model to copy.

comment:4 Changed 2 years ago by rwbarton

  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.