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 OAA25795; Thu, 12 Aug 2004 14:11:41 +0200 (MET DST) 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 OAA24143 for ; Thu, 12 Aug 2004 14:11:40 +0200 (MET DST) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i7CCBdmL032222 for ; Thu, 12 Aug 2004 14:11:39 +0200 Received: from ibm3.cicrp.jussieu.fr (ibm3.cicrp.jussieu.fr [134.157.15.3]) by shiva.jussieu.fr (8.12.11/jtpda-5.4) with ESMTP id i7CCAlh7085920 for ; Thu, 12 Aug 2004 14:10:47 +0200 (CEST) X-Ids: 166 Received: from ibm1.cicrp.jussieu.fr (ibm1.cicrp.jussieu.fr [134.157.15.1]) by ibm3.cicrp.jussieu.fr (8.8.8/jtpda/mob-V8) with ESMTP id OAA152422 for ; Thu, 12 Aug 2004 14:09:32 +0200 Received: from localhost (fernande@localhost) by ibm1.cicrp.jussieu.fr (8.8.8/jtpda/mob-v8) with ESMTP id OAA704578 for ; Thu, 12 Aug 2004 14:09:10 +0200 X-Authentication-Warning: ibm1.cicrp.jussieu.fr: fernande owned process doing -bs Date: Thu, 12 Aug 2004 14:09:10 +0200 (DST) From: Diego Olivier Fernandez Pons X-X-Sender: fernande@ibm1 To: caml-list@inria.fr Subject: Re: [Caml-list] getting the type of a polymorphic data ? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 411B5E7B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at shiva.jussieu.fr with ID 411B5E47.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Antivirus: scanned by sophie at shiva.jussieu.fr X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pons:01 pons:01 etu:99 caml-list:01 intset:01 isomorphic:01 hashtbl:01 hash:01 isomorphic:01 hashtbl:01 hash:01 'obj:01 fernandez:01 fernandez:01 bool:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Bonjour, > The problem is that I don't know how to catch the type of a > polymorphic data structure (is this even possible with some magic ?) > to be able to write something like > > let x' = match (somemagic.type_of x) with > | INT -> IntSet.from_poly x > | FLOAT -> FloatIntervalSet.from_poly x > | _ -> x I have just realized I really do not need the 'type' of the polymorphic data, just to know if it is isomorphic to integers (to be able to properly use Hashtbl.hash) It seems that Obj.is_int does exactly that (determining if a type is isomorphic to a subset of integers). Objective Caml version 3.08.0 # Obj.is_int (Obj.repr 'a');; - : bool = true # type x = A | B;; type x = A | B # Obj.is_int (Obj.repr A);; - : bool = true # Obj.is_int (Obj.repr 1);; - : bool = true # Obj.is_int (Obj.repr "a");; - : bool = false # type x = A of int * int | B of int;; type x = A of int * int | B of int # Obj.is_int (Obj.repr (A (1, 0)));; - : bool = false Is it reasonable to admit that if Obj.is_int is true for x and y then Hashtbl.hash is injective ? hash x = hash y => x = y (for structural polymorphic equality) In other terms does 'Obj.is_int x' implies that x is 'perfectly hashable' ? Diego Olivier ------------------- 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