#2528: nub not as reliable as nubBy
-------------------------------+--------------------------------------------
    Reporter:  jdressel        |        Owner:          
        Type:  bug             |       Status:  reopened
    Priority:  normal          |    Milestone:          
   Component:  libraries/base  |      Version:  6.8.2   
    Severity:  minor           |   Resolution:          
    Keywords:                  |     Testcase:          
Architecture:  Unknown         |           Os:  Linux   
-------------------------------+--------------------------------------------
Comment (by jdressel):

 Jeremy is correct: I forgot a case in my definition of (==) that makes it
 not completely symmetric for second layer commutative equivalence (oops).

 The relevant demonstration for the example case that failed in the linked
 codepaste is:
 {{{
   *Main> let a = Branch (Branch (Leaf (Just 9)) Add (Leaf (Just 9))) Add
 (Leaf (Just 2))
   *Main> let b = Branch (Leaf (Just 9)) Add (Branch (Leaf (Just 9)) Add
 (Leaf (Just 2)))
   *Main> a == b
   True
   *Main> b == a
   False
   *Main> List.nubBy (==) [a,b]
   [((9+9)+2)]
   *Main> List.nub [a,b]
   [((9+9)+2),(9+(9+2))]
 }}}

 I guess the lack of symmetry in (==) causes the difference in behavior,
 which makes more sense to me now.

 However, Adrian is also correct, the difference in behavior between "nub"
 and "nubBy (==)" is what startled me.  I would have found the bug in my
 code eventually (especially after unit testing).

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2528#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to