Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007502OCamlstandard librarypublic2017-03-09 10:362017-05-02 12:06
Reportereponier 
Assigned Tofrisch 
PrioritylowSeverityminorReproducibilityalways
StatusresolvedResolutionwon't fix 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0007502: (=) does not use physical equality unlike compare
DescriptionFor some reason, I was playing with:

let rec l = 1 :: l;;

And I tried to manipulate it. But while "compare l l" returns 0 instantaneously, "l = l" loops infinitely. I do not know if structural equality is supposed to use physical equality as a speed-up, but I find this difference in behaviour surprising. The same happens with (<) ad (>).

Moreover, in an interactive session (utop or ocaml), the loop is not interrupted by pressing ctrl+c.
TagsNo tags attached.
Attached Files

- Relationships
related to 0003921acknowledged structural equality for cyclic data structure cannot be interrupted 
related to 0007524acknowledged Add warning when using '=' in for none immediate values 

-  Notes
(0017606)
eponier (reporter)
2017-03-09 10:37

Tested on 4.04.0.
(0017607)
octachron (developer)
2017-03-09 10:56

There is at least a documentation mismatch between this behavior and the description of compare in the manual that claims compatibily between (=) and compare except for NaN.
(0017608)
frisch (developer)
2017-03-09 11:05

> I do not know if structural equality is supposed to use physical equality as a speed-up, but I find this difference in behaviour surprising.

`x = y` has a different semantics than `compare x y = 0`, and it cannot use physical equality as a "shortcut". The reason is related to floating points, for which `nan = nan` should be false even though the two arguments are physically equal, but one wants `compare nan nan` to return 0. And it has been decided that the same property should hold for nested floats as well, i.e. `let x = ("", nan) in x = x` should be false, but `let x = ("", nan) in compare x x` should be 0. Basically, (=) is *not* an equivalence relation (reflexivity does not hold) while `(fun x y -> compare x y = 0)` is (on its definition domain).

Honestly, I think it would be better to make (=) reflexive(and use physical equality as a short-cut) and to provide an explicit comparison function on floats using IEEE semantics. But I don't believe such proposal has any chance to be accepted. So I'm "resolving" this ticket for now.

- Issue History
Date Modified Username Field Change
2017-03-09 10:36 eponier New Issue
2017-03-09 10:37 eponier Note Added: 0017606
2017-03-09 10:40 octachron Relationship added related to 0003921
2017-03-09 10:54 octachron Priority normal => low
2017-03-09 10:54 octachron Status new => confirmed
2017-03-09 10:54 octachron Category language features => standard library
2017-03-09 10:56 octachron Note Added: 0017607
2017-03-09 11:05 frisch Note Added: 0017608
2017-03-09 11:05 frisch Status confirmed => resolved
2017-03-09 11:05 frisch Resolution open => won't fix
2017-03-09 11:05 frisch Assigned To => frisch
2017-05-02 12:06 dra Relationship added related to 0007524


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker