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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 5DE15BC0A for ; Mon, 29 Jan 2007 22:23:31 +0100 (CET) Received: from smtp.janestcapital.com (www.janestcapital.com [66.155.124.107]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0TLNT0U005105 for ; Mon, 29 Jan 2007 22:23:30 +0100 Received: from [192.168.250.117] [209.213.205.130] by janestcapital.com with ESMTP (SMTPD-9.10) id A5CF0228; Mon, 29 Jan 2007 16:23:27 -0500 Message-ID: <45BE65CF.7070806@janestcapital.com> Date: Mon, 29 Jan 2007 16:23:27 -0500 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Cc: Simon Frost , Caml List Subject: Re: [Caml-list] Equality of functional values References: <1170104645.4564.304.camel@penguin.local> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45BE65D1.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; val:01 bool:01 bool:01 allocates:01 heap:01 equality:01 equality:01 wrote:01 caml-list:01 functions:01 functions:01 int:01 int:01 partially:02 functional:02 Tom wrote: > It's hard to perform equality on functional values, as it is hard to > confirm two functions being the same... (even if you know the > mathematical definition of the function, thus even harder if you only > know the machine representation of it...). The best way around is to > use == equality (= is structural equality, while == is referential > equality - whether two names point to the same address in the memory), > which might return false often, but will never fail on functional > values. So I guess it's best you edit the source code (if you can) and > change it... > The problem with this is that it fails on partially applied functions. For example: # let f x y = x + y;; val f : int -> int -> int = # f == f;; - : bool = true # (f 1) == (f 1);; - : bool = false # This happens for the same reasons that: # 1. == 1.;; - : bool = false # does. Basically, both the expressions 1. and (f 1) allocate blocks on the heap. Evaluating them twice allocates different blocks, and thus referential comparisons return false. My general advice is don't depend upon equality of functions. Brian