From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id CF8E0BBAF for ; Fri, 25 Jul 2008 00:15:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAD+ciEjUVZsV/2dsb2JhbACzBQ X-IronPort-AV: E=Sophos;i="4.31,248,1215381600"; d="scan'208";a="13430702" Received: from cerberus.snarc.org ([212.85.155.21]) by mail2-smtp-roc.national.inria.fr with ESMTP; 25 Jul 2008 00:15:42 +0200 Received: by cerberus.snarc.org (Postfix, from userid 1000) id 7D487129E7; Thu, 24 Jul 2008 23:15:27 +0100 (BST) Date: Thu, 24 Jul 2008 23:15:27 +0100 From: Vincent Hanquez To: Raj Bandyopadhyay Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] equality operators in OCaml Message-ID: <20080724221527.GA23162@snarc.org> References: <4888D7B7.8030703@rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4888D7B7.8030703@rice.edu> X-Warning: Email may contain unsmilyfied humor and/or satire. User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Spam: no; 0.00; ocaml:01 ocaml:01 pointer:01 byterun:01 val:01 equality:01 equality:01 char:01 wrote:01 caml-list:01 int:01 caml:02 match:02 jul:05 thu:05 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