From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: "Harrison, John R" <johnh@ichips.intel.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Are you sure the new "=" of 3.08 is good ?
Date: Sat, 9 Oct 2004 10:58:06 +0200 [thread overview]
Message-ID: <20041009085806.GB17072@yquem.inria.fr> (raw)
In-Reply-To: <012676D607FCF54E986746512C22CE7D0FE7B8@orsmsx407>
> 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
Pervasives.compare 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 = (Pervasives.compare 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 = (Pervasives.compare 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 Pervasives.compare.
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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2004-10-09 8:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-08 16:35 Harrison, John R
2004-10-08 17:34 ` Damien Doligez
2004-10-09 8:58 ` Xavier Leroy [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-10-09 18:10 Harrison, John R
2004-10-09 17:56 Harrison, John R
2004-10-08 16:25 Harrison, John R
2004-10-08 2:54 Harrison, John R
2004-10-08 5:49 ` Christophe Raffalli
2004-10-08 6:54 ` David Brown
2004-10-07 21:14 Christophe Raffalli
2004-10-08 7:38 ` Jean-Christophe Filliatre
2004-10-08 8:31 ` Christophe Raffalli
2004-10-08 15:10 ` Damien Doligez
2004-10-08 9:37 ` Sébastien Furic
2004-10-08 15:54 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041009085806.GB17072@yquem.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=johnh@ichips.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox