From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9D5F6BC84 for ; Mon, 18 Apr 2005 21:12:20 +0200 (CEST) Received: from ptb-relay02.plus.net (ptb-relay02.plus.net [212.159.14.213]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j3IJCKN5003302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 18 Apr 2005 21:12:20 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay02.plus.net with esmtp (Exim) id 1DNbfP-0006Ke-RF for caml-list@yquem.inria.fr; Mon, 18 Apr 2005 19:12:19 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] type of == Date: Mon, 18 Apr 2005 15:28:29 +0100 User-Agent: KMail/1.7.1 References: <42637B63.1070608@ifp.fr> <200504181227.07108.jon@ffconsultancy.com> <001901c5440f$ce1a5e80$14b2a8c0@wiko> In-Reply-To: <001901c5440f$ce1a5e80$14b2a8c0@wiko> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200504181528.29618.jon@ffconsultancy.com> X-Miltered: at nez-perce with ID 42640694.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 rossberg:01 ocaml-only:01 bool:01 val:01 bool:01 ocaml:01 ocaml:01 abstraction:01 frog:98 wrote:01 equality:01 equality:01 polymorphic:01 abstract:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Monday 18 April 2005 13:11, Andreas Rossberg wrote: > Either when 'a and 'b happen to be instantiated to the same type, Yes, I realised this just after posting (thanks Diego!). > or when the representation happens to be the same, e.g. 0 == false. Assuming this is for an OCaml-only program, it sounds as though the "other" possible types 'a and 'b should be put into a single variant type. Then you can use "'a -> 'a -> bool" with "'a = your variant type". Does that make any sense? :-) You'd have to indirect the physical equality once though, e.g.: # type ('a, 'b) a = A of 'a | B of 'b;; type ('a, 'b) a = A of 'a | B of 'b # let compare_a x y = match x, y with A x, A y -> x == y | B x, B y -> x == y | _ -> false;; val compare_a : ('a, 'b) a -> ('a, 'b) a -> bool = A good excuse not to do this would be when you're writing a veneer between OCaml and C in OCaml. > The latter also provides a good argument against making physical equality > too polymorphic. It would break abstraction, much worse than it does > already. In particular, a program's meaning could depend on implementation > details (like false being represented by 0) in very questionable ways. Yes, although this is already the case when applying "=" to abstract types (implementation of the type in that case, rather than of the language itself). -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists