caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Vincent Hanquez <tab@snarc.org>
To: Raj Bandyopadhyay <rajb@rice.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] equality operators in OCaml
Date: Thu, 24 Jul 2008 23:15:27 +0100	[thread overview]
Message-ID: <20080724221527.GA23162@snarc.org> (raw)
In-Reply-To: <4888D7B7.8030703@rice.edu>

On Thu, Jul 24, 2008 at 02:27:51PM -0500, Raj Bandyopadhyay wrote:
> 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?

yes. only valid for object that are in blocks though (int, char are not).
for object not in block, you end up with a simple =

> 2) Where can I find the code implementing the '==' operator in the OCaml  
> code?

byterun/compare.c : caml_equal which call compare_val with total=0 (which
means to not compare inside blocks)

> 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 == is the fastest one. but that's just based on how the thing
works compare to the others compare, not on empirical benchs.

-- 
Vincent


  reply	other threads:[~2008-07-24 22:15 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 ` Vincent Hanquez [this message]
2008-07-24 22:32 ` [Caml-list] " Jon Harrop
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=20080724221527.GA23162@snarc.org \
    --to=tab@snarc.org \
    --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).