Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] polymorphic (<)

5 views
Skip to first unread message

Jacques Le Normand

unread,
Apr 21, 2010, 5:07:49 PM4/21/10
to caml-list caml-list
Hello caml-list,
Why doesn't (<) check for physical equality before traversing the
structures?
--Jacques L.

Martin Jambon

unread,
Apr 21, 2010, 5:32:06 PM4/21/10
to Jacques Le Normand, 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/

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

0 new messages