You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7502 Reporter: eponier Assigned to:@alainfrisch Status: resolved (set by @alainfrisch on 2017-03-09T10:05:23Z) Resolution: won't fix Priority: low Severity: minor Category: standard library Related to:#3921#7524
Bug description
For 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.
The text was updated successfully, but these errors were encountered:
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.
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.
Original bug ID: 7502
Reporter: eponier
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2017-03-09T10:05:23Z)
Resolution: won't fix
Priority: low
Severity: minor
Category: standard library
Related to: #3921 #7524
Bug description
For 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.
The text was updated successfully, but these errors were encountered: