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 TAA30138; Mon, 31 Mar 2003 19:33:12 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA30382 for ; Mon, 31 Mar 2003 19:33:11 +0200 (MET DST) Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id h2VHXA926107 for ; Mon, 31 Mar 2003 19:33:10 +0200 (MET DST) Received: (qmail 18485 invoked by uid 36130); 31 Mar 2003 17:33:08 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 31 Mar 2003 17:33:08 -0000 Date: Mon, 31 Mar 2003 09:33:08 -0800 (PST) From: brogoff@speakeasy.net To: Neel Krishnaswami cc: Ocaml Mailing List Subject: Re: [Caml-list] How can I check for the use of polymorphic equality? In-Reply-To: <16008.29181.437301.517752@h00045a4799d6.ne.client2.attbi.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 caml-list:01 conundrum:01 val:01 tagging:01 neel:01 krishnaswami:01 bug:01 neelk:01 faq:01 beginner's:01 beginners:01 bin:01 compiler:01 caml-bugs:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Quite a conundrum, since equality wouldn't be polymorphic if it didn't work for all (non-functional) values! Following that silly parenthetical comment, you could explicitly tag values with a functional fields. As long as they are the first field you're OK (try swapping the field order if you don't see what I mean). # type 'a no_eq = { no_eq_tag : unit -> int; data : 'a };; type 'a no_eq = { no_eq_tag : unit -> int; data : 'a; } # let x0 = {data = 0; no_eq_tag = fun () -> 0};; val x0 : int no_eq = {no_eq_tag = ; data = 0} # let x1 = {data = 1; no_eq_tag = fun () -> 1};; val x1 : int no_eq = {no_eq_tag = ; data = 1} # x0 = x1;; Exception: Invalid_argument "equal: functional value". You can use tuples isntead of records if you wish too. BTW, this tagging strikes me as very ugly. A cleaner solution IMO is be to use your own order data type patterned after every other FPL, type order = Less | Equal | Greater, or your own equality data type, to avoid this if it starts becoming a problem. Equality is a rough edge in just about every programming language. -- Brian On Mon, 31 Mar 2003, 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? > > -- > Neel Krishnaswami > neelk@alum.mit.edu > > ------------------- > 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 > ------------------- 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