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 VAA14087; Thu, 3 Apr 2003 21:44:44 +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 VAA13661 for ; Thu, 3 Apr 2003 21:44:42 +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 h33Jif517708 for ; Thu, 3 Apr 2003 21:44:41 +0200 (MET DST) Received: from kenai.yapper.org (kenai.yapper.org [67.120.175.90]) by yukon.yapper.org (Postfix) with ESMTP id DDB9CC64; Thu, 3 Apr 2003 11:44:39 -0800 (PST) Received: from cs.caltech.edu (localhost [127.0.0.1]) by kenai.yapper.org (Postfix) with ESMTP id 985E2D58; Thu, 3 Apr 2003 11:44:39 -0800 (PST) Message-ID: <3E8C8F27.1070001@cs.caltech.edu> Date: Thu, 03 Apr 2003 11:44:39 -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: Ocaml Mailing List Subject: Re: [Caml-list] How can I check for the use of polymorphic equality? References: <16008.29181.437301.517752@h00045a4799d6.ne.client2.attbi.com> In-Reply-To: <16008.29181.437301.517752@h00045a4799d6.ne.client2.attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; hickey:01 caml-list:01 neel:01 krishnaswami:01 bug:01 pervasives:01 runtime:01 626:99 792:99 compiler:01 equality:01 sml:01 polymorphic:01 caltech:01 typechecker:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Neel Krishnaswami wrote: > I spent the last few hours tracking down a bug that was the result of > accidentally using the polymorphic equality rather than a custom > comparison function. Is there any way I can tell the compiler not to > allow the use of polymorphic equality at certain types, or even just > to raise an exception when it tries to compare values of those types? This has been bothering me for quite some time. There are times when I would like to modify an implementation to use a coarser comparison function than Pervasives.compare. This requires manually finding all uses of =, <, etc. and modifying them to use the new comparison function. It would be great if the typechecker would help, since it is easy to forget and reintroduce the use of = by accident. I suppose the real answer would be to extend the type system with equality types, similar to those in SML. In the meantime, I use a hack to help catch errors at runtime. The idea is this. 1. The type you care about is probably abstract. 2. Add an abstract value to the data in your type, so that equality will fail (at runtime). Suppose that your type is declared like this: type t = t1 let create ... : t = e Modify this as follows: type t = t1 * Obj.t let create ... : t = let bogus = Obj.new_block Obj.abstract_tag 1 in e, bogus You'll see the following behavior: let o1 = create ... in let o2 = create ... in o1 = o2 Exception: Invalid_argument "equal: abstract value" To find these errors, you'll probably want to use exception tracing. Use byte-code, and set the environment variable OCAMLRUNPARAM=b. The "bogus" values are wasted space, so you may want to remove this wrapper code if you are confident that you found all the errors. 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