#2496: Invalid Eq/Ord instances in Data.Version
-------------------------+--------------------------------------------------
    Reporter:  guest     |       Owner:                
        Type:  bug       |      Status:  new           
    Priority:  normal    |   Component:  libraries/base
     Version:  6.8.3     |    Severity:  normal        
    Keywords:            |    Testcase:                
Architecture:  Multiple  |          Os:  Multiple      
-------------------------+--------------------------------------------------
 (From Adrian Hey)

 In Data.Version we have:

 {{{
 data Version =
   Version {versionBranch :: [Int]
           ,versionTags :: [String]
           }

 instance Eq Version where
   v1 == v2  =  versionBranch v1 == versionBranch v2
                 && sort (versionTags v1) == sort (versionTags v2)
                 -- tags may be in any order

 instance Ord Version where
   v1 `compare` v2 = versionBranch v1 `compare` versionBranch v2
 }}}

 The "laws" for valid Eq/Ord instances were argued about recently but the
 H98 report seems reasonably clear that (==) is supposed to test for
 equality and the compare method is supposed to define a total ordering.
 There is also an implied but not explicitly stated law that:

 {{{
  (x == y = True)  <-> (x `compare` y = EQ)
 }}}
 and also this I guess..
 {{{
  (x == y = False)  <-> ~(x `compare` y = EQ)
 }}}

 This law is implied by the Eq constraint on the Ord class (which seems to
 serve no purpose otherwise).

 See also:
 [http://www.haskell.org/pipermail/haskell-prime/2008-March/002330.html]

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2496>
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