GHC: Ticket #3281: The order of arguments to the function passed to nubBy got swapped somehow
http://ghc.haskell.org/trac/ghc/ticket/3281
<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/3281
Trac 1.0.1guestSat, 06 Jun 2009 05:26:19 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/3281#comment:1
http://ghc.haskell.org/trac/ghc/ticket/3281#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>duplicate</em>
</li>
</ul>
Ticket