GHC: Ticket #3280: The order of arguments to the function passed to nubBy got swapped somehow
http://ghc.haskell.org/trac/ghc/ticket/3280
<p>
According to the Report:
</p>
<pre class="wiki"> nubBy :: (a -> a -> Bool) -> [a] -> [a]
nubBy eq [] = []
nubBy eq (x:xs) = x : nubBy eq (filter (\y -> not (eq x y)) xs)
</pre><p>
Hence, we should have that
</p>
<pre class="wiki">nubBy (<) (1:2:[])
= 1 : nubBy (<) (filter (\y -> not (1 < y)) (2:[]))
= 1 : nubBy (<) []
= 1 : []
</pre><p>
However in ghc-6.10.3:
</p>
<pre class="wiki">Prelude Data.List> nubBy (<) [1,2]
[1,2]
</pre><p>
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.
</p>
<p>
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.
</p>
<ul><li>Cale
</li></ul>en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/3280
Trac 1.2simonmarTue, 09 Jun 2009 12:01:30 GMTdifficulty set
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:1
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
</ul>
<p>
See <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/2528" title="#2528: bug: documentation for nub and nubBy should be corrected, extended or removed. (closed: fixed)">#2528</a> for why this was changed. I have no opinion, fight it out amongst yourselves :-)
</p>
TicketduncanTue, 09 Jun 2009 19:41:01 GMT
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:2
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:2
<p>
Clearly we must have <code>nub = nubBy (==)</code>. So perhaps that means we need to fix <code>nub</code> to bring it in line with the previous definition of <code>nubBy</code> (if that's agreed to be the sensible definition).
</p>
TicketiglooSun, 12 Jul 2009 17:35:19 GMTmilestone set
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:3
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:3
<ul>
<li><strong>milestone</strong>
set to <em>6.12.1</em>
</li>
</ul>
<p>
Does someone want to make a proposal for this please?
</p>
TicketiglooSat, 21 Nov 2009 00:43:06 GMTstatus changed; failure, resolution set
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:4
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:4
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
<p>
My understanding is that <code>nub</code> and <code>nubBy</code> are currently consistent, so I'm closing this ticket. If you want to propose different behaviour, please see <a class="ext-link" href="http://www.haskell.org/haskellwiki/Library_submissions"><span class="icon"></span>http://www.haskell.org/haskellwiki/Library_submissions</a>
</p>
TicketHerbert Valerio Riedel <hvr@…>Fri, 07 Nov 2014 16:48:55 GMT
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:5
http://ghc.haskell.org/trac/ghc/ticket/3280#comment:5
<p>
In <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/a2e7bbfe7656cf7dbf1af4da5c077ac0b5d41127/ghc" title="Preserve argument order to (==)/eq in nub and nubBy
This makes nub ...">a2e7bbfe7656cf7dbf1af4da5c077ac0b5d41127/ghc</a>:
</p>
<pre class="message">Preserve argument order to (==)/eq in nub and nubBy
This makes nub and nubBy behave as specified in the Haskell 98 Report.
This reverts 0ad9def53842e86fb292eccb810190711c42d7c5, and
fixes #3280, #7913 and #2528 (properly).
Before this change, the output of `T2528` was (4x wrong):
```
[A,B]
[1,2]
False
False
```
Reviewed By: dfeuer, ekmett, austin, hvr
Differential Revision: https://phabricator.haskell.org/D238</pre>
Ticket