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=1.7 required=5.0 tests=AWL,FORGED_MUA_OUTLOOK autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id DEA20BBAF for ; Fri, 25 Jul 2008 00:32:40 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AssTAMCfiEjUnw7UaWdsb2JhbACBVIdxgiWGaRICHgOffwM X-IronPort-AV: E=Sophos;i="4.31,248,1215381600"; d="scan'208";a="15433764" Received: from ptb-relay01.plus.net ([212.159.14.212]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 25 Jul 2008 00:32:40 +0200 Received: from [80.229.56.224] (helo=frodo) by ptb-relay01.plus.net with esmtpa (Exim) id 1KM9MV-0001gv-Hg; Thu, 24 Jul 2008 23:32:39 +0100 Message-ID: <732669E74A7B4E49A8F225F86C335C5E@frodo> From: "Jon Harrop" To: "Raj Bandyopadhyay" , References: <4888D7B7.8030703@rice.edu> Subject: Re: [Caml-list] equality operators in OCaml Date: Thu, 24 Jul 2008 23:32:36 +0100 Organization: Flying Frog Consultancy Ltd. MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 x-mimeole: Produced By Microsoft MimeOLE V6.00.2900.5512 X-Plusnet-Relay: 63f73f9b6c8fb5e19305f76494369a14 X-Spam: no; 0.00; ocaml:01 ocaml:01 pointer:01 structurally:01 ocaml's:01 statically:01 cheers:01 sml:01 sml:01 equality:01 equality:01 compile:01 caml-list:01 functions:01 data:02 From: "Raj Bandyopadhyay" > 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.