Ticket #3280 (closed bug: wontfix)

Opened 3 years ago

Last modified 2 years ago

The order of arguments to the function passed to nubBy got swapped somehow

Reported by: guest Owned by:
Priority: normal Milestone: 6.12.1
Component: libraries/base Version: 6.10.3
Keywords: Cc: cgibbard@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

According to the Report:

  nubBy            :: (a -> a -> Bool) -> [a] -> [a]
  nubBy eq []      =  []
  nubBy eq (x:xs)  =  x : nubBy eq (filter (\y -> not (eq x y)) xs)

Hence, we should have that

nubBy (<) (1:2:[])
= 1 : nubBy (<) (filter (\y -> not (1 < y)) (2:[]))
= 1 : nubBy (<) []
= 1 : []

However in ghc-6.10.3:

Prelude Data.List> nubBy (<) [1,2]
[1,2]

The order of the parameters to the function which is passed to nubBy is *important* since the function might not be an equivalence relation. nubBy is more generally useful for sieving even when the relation is not symmetric. groupBy, for a similar reason, has applications for grouping beyond those provided by equivalence relations, and I think we should be able to rely on its behaviour.

Moreover, I contend that the Report's order is more sensible, since the parameters to the relation stay in the left-to-right order in which they occurred in the list.

  • Cale

Change History

Changed 3 years ago by simonmar

  • difficulty set to Unknown

See #2528 for why this was changed. I have no opinion, fight it out amongst yourselves :-)

Changed 3 years ago by duncan

Clearly we must have nub = nubBy (==). So perhaps that means we need to fix nub to bring it in line with the previous definition of nubBy (if that's agreed to be the sensible definition).

Changed 3 years ago by igloo

  • milestone set to 6.12.1

Does someone want to make a proposal for this please?

Changed 2 years ago by igloo

  • status changed from new to closed
  • failure set to None/Unknown
  • resolution set to wontfix

My understanding is that nub and nubBy are currently consistent, so I'm closing this ticket. If you want to propose different behaviour, please see  http://www.haskell.org/haskellwiki/Library_submissions

Note: See TracTickets for help on using tickets.