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 VAA10753; Fri, 4 Apr 2003 21:05:37 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA10864 for ; Fri, 4 Apr 2003 21:05:35 +0200 (MET DST) Received: from yukon.yapper.org (adsl-67-120-175-89.dsl.lsan03.pacbell.net [67.120.175.89]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h34J5X509619; Fri, 4 Apr 2003 21:05:34 +0200 (MET DST) Received: from kenai.yapper.org (kenai.yapper.org [67.120.175.90]) by yukon.yapper.org (Postfix) with ESMTP id 8E9747AB; Fri, 4 Apr 2003 11:05:32 -0800 (PST) Received: from cs.caltech.edu (localhost [127.0.0.1]) by kenai.yapper.org (Postfix) with ESMTP id 055C3D57; Fri, 4 Apr 2003 11:05:31 -0800 (PST) Message-ID: <3E8DD77B.2010804@cs.caltech.edu> Date: Fri, 04 Apr 2003 11:05:31 -0800 From: Jason Hickey Organization: Caltech User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20030211 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Pierre Weis Cc: Chris Hecker , caml-list@inria.fr Subject: Re: [Caml-list] How can I check for the use of polymorphic equality? References: <200304040846.KAA31411@pauillac.inria.fr> In-Reply-To: <200304040846.KAA31411@pauillac.inria.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; hickey:01 caml-list:01 pierre:01 weis:01 generic:01 predicate:01 pervasives:01 debugging:01 m-x:01 inference:01 fixpoint:01 626:99 792:99 bool:01 equality:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Pierre Weis wrote: >>and more importantly b) means you can't use = anywhere, doesn't it? > > No: it means you have to do something more than just writing = when > you need to call the predefined generic equality. You first have to > think if there is not another predicate that is not more appropriate > to the situation, and if there is none, you just have to insert a mere > > let ( = ) = Pervasives.( = ) in > > before each relevant occurrence of ( = ). Those single lines can be > easily removed after proper debugging (use an emacs keyboard macro + a > M-x grep -n -e ... *.ml). > > ... > Pierre Weis One really nice thing about your solution is that we can get type inference to catch uses of =. But it can be awkward because we still need relations on base types. Imagine that we have a Set module that should use Set.equal, not =. Consider the fixpoint code below. type empty let (=) (x : empty) (y : empty) = assert false let (>) (x : empty) (y : empty) = assert false ... let rec fixpoint s1 s2 = if Set.equal s1 s2 then s1 (* Can't use >, so use Pervasives.(>) directly *) else if Pervasives.(>) (Set.cardinal s1) (Set.cardinal s2) then fixpoint (f s1) s2 else fixpoint s1 (f s2) It can get ugly if we have to use the Pervasives.(=) a lot. Of course, we could be a little smarter, and define something like the following for each of the base types. let (=@) : int -> int -> bool = Pervasives.(=) Perhaps even let (=$) : 'a set -> 'a set -> bool = Set.equal This might be a compromise, though remembering all the equality suffixes would be a hassle. Jason -- Jason Hickey http://www.cs.caltech.edu/~jyh Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners