* polymorphic (<)
@ 2010-04-21 21:07 Jacques Le Normand
2010-04-21 21:31 ` [Caml-list] " Martin Jambon
0 siblings, 1 reply; 2+ messages in thread
From: Jacques Le Normand @ 2010-04-21 21:07 UTC (permalink / raw)
To: caml-list caml-list
[-- Attachment #1: Type: text/plain, Size: 108 bytes --]
Hello caml-list,
Why doesn't (<) check for physical equality before traversing the
structures?
--Jacques L.
[-- Attachment #2: Type: text/html, Size: 125 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] polymorphic (<)
2010-04-21 21:07 polymorphic (<) Jacques Le Normand
@ 2010-04-21 21:31 ` Martin Jambon
0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambon @ 2010-04-21 21:31 UTC (permalink / raw)
To: Jacques Le Normand; +Cc: caml-list caml-list
Jacques Le Normand wrote:
> Hello caml-list,
> Why doesn't (<) check for physical equality before traversing the
> structures?
If I remember correctly it used to be the case in older versions of OCaml, but
it changed because of the standard behavior expected from NaN float values.
The comparison of a NaN value with any other float should always return false,
and therefore the structural comparison of any data structure containing a NaN
with itself should also return false:
# let x = Some [ nan ];;
val x : float list option = Some [nan]
# x = x;;
- : bool = false
# x == x;;
- : bool = true
The solution to your problem is to use Pervasives.compare instead of the
comparison operators:
# compare x x;;
- : int = 0
Martin
--
http://mjambon.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-04-21 21:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-21 21:07 polymorphic (<) Jacques Le Normand
2010-04-21 21:31 ` [Caml-list] " Martin Jambon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox