
Malcolm Wallace wrote:
Proposal: that values of the type Data.Version.Version should compare equal, by ignoring trailing zeros. Thus 1.2.0 == 1.2, rather than 1.2.0 > 1.2
I see advantages and disadvantages. Advantages: * matches intuitive understanding of versions * lets us drop trailing zeroes in version numbers Disadvantages: * version ordering is slightly harder to explain Is there a precedent anywhere else for doing this?
[In Data.Version, make equality comparisons independent of trailing zeros. Malcolm.Wallace@cs.york.ac.uk**20071025161240] { hunk ./Data/Version.hs 122 - v1 == v2 = versionBranch v1 == versionBranch v2 + v1 == v2 = branchEq (versionBranch v1) (versionBranch v2) hunk ./Data/Version.hs 125 + where + branchEq :: [Int] -> [Int] -> Bool + branchEq [] [] = True + branchEq vs [] = all (==0) vs + branchEq [] vs = all (==0) vs + branchEq (v:vs) (w:ws) = v==w && branchEq vs ws hunk ./Data/Version.hs 133 - v1 `compare` v2 = versionBranch v1 `compare` versionBranch v2 - + v1 `compare` v2 = versionBranch v1 `cmpBranch` versionBranch v2 + where + cmpBranch [] [] = EQ + cmpBranch vs [] | all (==0) vs = EQ + | otherwise = GT + cmpBranch [] vs | all (==0) vs = EQ + | otherwise = LT + cmpBranch (v:vs) (w:ws) | v==w = cmpBranch vs ws + | otherwise = compare v w + }
Wouldn't the implementation be simpler if you added a dropTrailingZeros function, and just applied it before comparing? That would more obviously match the informal description too. Cheers, Simon