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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DDED4BC0B for ; Tue, 30 Jan 2007 21:30:09 +0100 (CET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0UKU9YR012321 for ; Tue, 30 Jan 2007 21:30:09 +0100 Received: from [84.59.105.120] (helo=gate.lan.gerd-stolpmann.de) by mrelayeu.kundenserver.de (node=mrelayeu6) with ESMTP (Nemesis), id 0ML29c-1HBzcA1Zzi-0000oa; Tue, 30 Jan 2007 21:30:02 +0100 Received: from flakew.lan.gerd-stolpmann.de (fw.lan.gerd-stolpmann.de [192.168.1.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id 13846C05F; Tue, 30 Jan 2007 21:30:02 +0100 (CET) Subject: Re: [Caml-list] Equality of functional values From: Gerd Stolpmann To: Tom Cc: Chris King , caml-list@yquem.inria.fr, Jacques Carette In-Reply-To: References: <45BF691B.8090506@mcmaster.ca> <875c7e070701300923r362b1032sac4125fd2879f8ae@mail.gmail.com> Content-Type: text/plain Date: Tue, 30 Jan 2007 21:30:01 +0100 Message-Id: <1170189001.21265.9.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de login:a6865a839c0178d9aa0ce41878507ea2 X-Provags-ID2: V01U2FsdGVkX1+WnCxmeVipAjWE5fcN0AYEs2nbzrbXOPJEzIS5dsd0k3Jt3Xs+ifQavDICkG4KuqpaTG5YzCw+Jng6DxJNqVOGi5OTsJJIIu0pgYRq2vn3ex8/gjm4rX1K X-Miltered: at concorde with ID 45BFAAD1.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gerd:01 stolpmann:01 ocaml:01 pervasives:01 val:01 bool:01 bool:01 wishlist:01 compiler:01 emits:01 compares:01 compiler:01 gerd:01 stolpmann:01 viktoriastr:01 Am Dienstag, den 30.01.2007, 21:18 +0100 schrieb Tom: > I guess the "correct" way to do = equality would be to check for tag > (Obj.tag (Obj.repr x)), and if it isn't float (or float array) then == > equality would be performed first. The problem is that this would have > to be implemented by the OCaml developers, as the naive > implementation: > > let equal x y = > if Obj.tag (Obj.repr x) = Obj.double_tag then x = y > else > if x == y then true else x = y > > doesn't work, But let equal x y = Pervasives.compare x y = 0 works! > as it should be called recursively (comparing two lists of functions > will fail, because the functions would be compared by =, not by > equal). > > Actually, the implementation could be improved further, as it could > actually return true on examples such as > > # let f x y = x + y;; > val f : int -> int -> int = > # f == f;; > - : bool = true > # (f 1) = (f 1);; > - : bool = true > > because the parameters, passed to a closure, could be compared, too... > > Anyhow, this can be added to the wishlist :) I can fully understand that ( = ) fails on functional values. The additional test for floats would take a lot of time, given that equality is the most frequent test. A better improvement would be that the compiler emits a warning when there is the possibility that the equality test compares functional values. In my opinion this is a serious programming error, and the compiler should help to track it down. Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------