Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] equality testing in 3.08
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Matt Harren <matth@c...>
Subject: [Caml-list] equality testing in 3.08

I recently upgraded to OCaml 3.08, and ran into problems with the
changed implementation of structural equality.  To support NaN, the (=)
operator no longer checks for physical equality or its operands.  This
causes two problems:
  1) Our application runs 9% slower because comparison isn't as
efficient.  When x == y, checking "x = y" takes time proportional to the
size of the structure, instead of constant time.
  2) We've been cheating and using (=) on structures that may be cyclic.
This works fine on earlier versions of ocaml, because the structures
contain a unique identifier as their first field.  But now that
structural equality checks no longer begin with a physical equality
check, we can get an infinite loop.

To work around this, I've been defining
   let (=) x1 x2 : bool =
     (compare x1 x2) = 0
at the start of each file, since the "compare" function still starts
with a physical equality check.  Is there a better way to override a
definition in the Pervasives module?

Also, has there been any discussion of restoring the old meaning of (=)?
I know it breaks NaN, but the performance difference might make this
worthwhile, even if you have no sympathy for those of us who use = on
cyclic structures. :)


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: