Ticket #2496 (new bug)

Opened 5 years ago

Last modified 4 months ago

Invalid Eq/Ord instances in Data.Version

Reported by: guest Owned by: duncan
Priority: normal Milestone: _|_
Component: libraries/base Version: 6.8.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

(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

Change History

Changed 5 years ago by duncan

See also the thread on cabal-devel starting with:  http://haskell.org/pipermail/cabal-devel/2008-May/002818.html

The conclusion of the discussion was that we should either remove the tags completely, or at minimum change the Eq instance to consider only the versionBranch. I was going to put a proposal to removing them through the libraries submission process. I suppose I should get round to doing that.

Changed 5 years ago by igloo

  • owner set to duncan.coutts@…
  • difficulty set to Unknown
  • milestone set to _|_

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Multiple to Unknown/Multiple

Changed 4 months ago by morabbin

  • failure set to None/Unknown

Data.Version in base-4.6.0.1 still has the quoted instance for Eq. Not clear if there's been a library proposal.

Changed 4 months ago by igloo

  • owner changed from duncan.coutts@… to duncan
Note: See TracTickets for help on using tickets.