From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA05761; Mon, 23 Apr 2001 13:57:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA05873 for caml-list@pauillac.inria.fr; Mon, 23 Apr 2001 13:57:13 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA26385 for ; Fri, 20 Apr 2001 01:26:01 +0200 (MET DST) Received: from ganymede.or.intel.com (jffdns01.or.intel.com [134.134.248.3]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f3JNPxr25878 for ; Fri, 20 Apr 2001 01:26:00 +0200 (MET DST) Received: from ichips-ra.pdx.intel.com (ichips-ra.pdx.intel.com [10.7.8.35]) by ganymede.or.intel.com (8.9.1a+p1/8.9.1/d: relay.m4,v 1.36 2001/04/18 16:16:02 root Exp $) with ESMTP id XAA13472; Thu, 19 Apr 2001 23:25:45 GMT Received: from dhpc0010.pdx.intel.com (dhpc0010.pdx.intel.com [10.7.21.33]) by ichips-ra.pdx.intel.com (8.9.1a/8.9.1/d: internal.m4,v 1.2 1998/11/09 19:18:37 iwep Exp iwep $) with ESMTP id QAA07126; Thu, 19 Apr 2001 16:25:45 -0700 (PDT) Received: from ichips.intel.com (johnh@localhost [127.0.0.1]) by dhpc0010.pdx.intel.com (8.9.1a/8.9.1/d: client-ra.m4,v 1.1 1998/12/24 19:00:55 jamesw Exp jamesw $) with ESMTP id QAA09318; Thu, 19 Apr 2001 16:25:45 -0700 (PDT) Message-Id: <200104192325.QAA09318@dhpc0010.pdx.intel.com> To: "Francisco Valverde Albacete" cc: John Harrison , caml-list@inria.fr Subject: Re: [Caml-list] User-defined equality on types? In-reply-to: Your message of "Thu, 19 Apr 2001 19:44:37 PDT." <3ADF2405.4976B91E@tsc.uc3m.es> Date: Thu, 19 Apr 2001 16:25:40 -0700 From: John R Harrison Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi Francisco, | Have you considered using functors defining your datatype | structures? In that way you can customise the use of equality | throught the whole module with something like: | [...] Thanks for the suggestion; I hadn't considered using functors. But I'm not quite sure I understand your idea completely. I see how I can localize the instances of the custom equality operation, but it seems I still need to make explicit reference to a non-standard equality *outside* the module, and it doesn't happen "transparently", still less in composite data structures. This is the critical thing that I want. For example, suppose I have a type of integers modulo 2 with a non-canonical representation and a user-defined equality relation: module Mod2 = struct type z2 = Integer of int let (=) (Integer m) (Integer n) = (m - n) mod 2 = 0 let mk n = Integer n let dest(Integer n) = n mod 2 end;; I want all equality on type "z2" to use this defined equality relation, including on the appropriate fields of composite data structures where some but (maybe not all) components are of type "z2". But this doesn't happen by default: # let x = Mod2.mk 3 and y = Mod2.mk 5;; val x : Mod2.z2 = Mod2.Integer 3 val y : Mod2.z2 = Mod2.Integer 5 # x = y;; - : bool = false If I explicitly refer to Mod2.(=), then all is well: # Mod2.(=) x y;; - : bool = true But this doesn't happen automatically on composite data structures: # (x,1) = (y,1);; - : bool = false and if I open the module, the regular equality is hidden: # open Mod2;; # x = y;; - : bool = true # (x,1) = (x,2);; This expression has type Mod2.z2 * int but is here used with type Mod2.z2 Can I use your idea to set things up to do what I want? Btw, Alain Frisch's message reminded me that one would also like to be able to customize the generic hashing function to ensure it's substitutive w.r.t. the defined equality relation. Of course, the "z2" example is articifial. But there are lots of real situations where one might want types to be represented non-canonically. For example, I think the standard library's sets, represented by quasi-balanced trees, are non-canonical. John. ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr