From: "Jon Harrop" <jon@ffconsultancy.com>
To: "Raj Bandyopadhyay" <rajb@rice.edu>, <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] equality operators in OCaml
Date: Thu, 24 Jul 2008 23:32:36 +0100 [thread overview]
Message-ID: <732669E74A7B4E49A8F225F86C335C5E@frodo> (raw)
In-Reply-To: <4888D7B7.8030703@rice.edu>
From: "Raj Bandyopadhyay" <rajb@rice.edu>
> Hi OCaml folk
>
> I apologize if I've been asking too many questions on this list recently,
> but I'm working on a heavy OCaml application and need help sometimes.
>
> I am having a disagreement with a colleague about how the equality
> operators in OCaml work and am trying to resolve it conclusively.
>
> 1) I understand that the '==' operator is basically a pointer comparison
> i.e. a==b true iff a and b are the same entity. Is this true?
There are some complications here. Firstly, NaN has multiple representations
that may or may not be physically equal but is always structurally unequal
to itself. Secondly, OCaml's implicit allocation can make "same entity"
unclear, constant subexpressions (e.g. Some 3) may or may not be hoisted.
The only place I ever use == and != is when optimizing code in such a way
that unexpected results from those functions result in slow but still
correct code.
> 2) Where can I find the code implementing the '==' operator in the OCaml
> code?
Can you just compile it and look at the assembler? There are probably many
different outputs depending upon the statically resolved types.
> 3) In case I do want to check object identity and can use the == operator,
> would it be faster to use '==', '=' or a match statement?
I believe the == operator would be fastest. More often that not, you want <
and > so you end up augmenting your OCaml data structures with unique IDs
anyway.
Note that physical equality does not even exist in SML and the designers of
SML stand by that design decision. Perhaps it is best to avoid == in OCaml
altogether.
Cheers,
Jon.
next prev parent reply other threads:[~2008-07-24 22:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-24 19:27 Raj Bandyopadhyay
2008-07-24 22:15 ` [Caml-list] " Vincent Hanquez
2008-07-24 22:32 ` Jon Harrop [this message]
2008-07-25 1:40 ` Peng Zang
2008-07-25 10:34 ` Christophe TROESTLER
2008-07-25 12:04 ` Peng Zang
2008-07-25 20:14 ` Matthew William Cox
2008-07-25 22:27 ` Peng Zang
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=732669E74A7B4E49A8F225F86C335C5E@frodo \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
--cc=rajb@rice.edu \
/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;
as well as URLs for NNTP newsgroup(s).