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 PAA02508; Fri, 29 Jun 2001 15:12:40 +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 PAA02149 for ; Fri, 29 Jun 2001 15:12:39 +0200 (MET DST) Received: from mta01-svc.ntlworld.com (mta01-svc.ntlworld.com [62.253.162.41]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5TDCcj13500 for ; Fri, 29 Jun 2001 15:12:38 +0200 (MET DST) Received: from htec.demon.co.uk ([62.252.169.184]) by mta01-svc.ntlworld.com (InterMail vM.4.01.02.27 201-229-119-110) with ESMTP id <20010629131236.HVQY351.mta01-svc.ntlworld.com@htec.demon.co.uk> for ; Fri, 29 Jun 2001 14:12:36 +0100 Message-ID: <3B3C7F49.D058A72D@htec.demon.co.uk> Date: Fri, 29 Jun 2001 14:14:49 +0100 From: Chris Quinn X-Mailer: Mozilla 4.61 [en] (X11; I; Linux 2.4.0-test6 i686) X-Accept-Language: en MIME-Version: 1.0 CC: caml-list@inria.fr Subject: Re: [Caml-list] checking for same ctor type? References: <200106280240.TAA14693@smtp2-cm.mail.eni.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Pervasives.compare is fine for nullary constructors or where you don't mind the performance hit of the function recursing into the structure of the arguments. A more efficient equality predicate that is really just a cut down version of [compare]: module Kludge = struct let cmp (a: 't) (b: 't) = let a' = Obj.repr a and b' = Obj.repr b in match Obj.is_block a', Obj.is_block b' with | true,true -> Obj.tag a' = Obj.tag b' | false,false -> a' = b' | _ -> false end It of course relies on the physical representation of sum types. It has the merit of working on a type of any number of constructors, but the mis-merit of also operating over functions for instance! To constrain such a comparison to sum types would require it to be built into the compiler. Chris Q. ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr