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
RE: [Caml-list] Are you sure the new "=" of 3.08 is good ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-10-09 (08:58)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] Are you sure the new "=" of 3.08 is good ?
> For LCF-style theorem provers, I think it's quite important that when
> comparing terms (or similar tree structures) for equality, there should
> be a quick "yes" when two high-level subgraphs are pointer eq. [...]
> I guess like Christophe Raffalli I had just assumed this would be
> the case based on long experience with ML-family languages, rather than
> through any explicit discussion in the documentation.

I agree the behaviour your describe (x == y implies x = y) is very
reasonable.  Unfortunately, nan <> nan is also very reasonable, at
least if you believe in IEEE floats, and you cannot have both...

We agonized a long time on this issue before settling on the current
compromise: "=" is compatible with IEEE float equality, and implements the behaviour you expect (early stop if ==).

> Can you clarify what we need to do in order to guarantee this
> behaviour?

As I said in an earlier post, you can do

  let (=?) x y = ( x y = 0)

and use =? instead of = in places where you need the "early stop" behaviour.

I advise against Damien's suggestion of defining

  let (=) x y = ( x y = 0)

because the predefined "=" operator is known to the compiler and is
type-specialized to much more efficient code when comparing ints,
floats or strings.  No such type specialization takes place when "="
is defined in terms of

Of course, if the speed of equality is critical, you can also define
your own comparison functions for the types of interest, or even (as
Damien suggested) implement hash-consing.

Hope this clarifies the issue.

- Xavier Leroy

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