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 EAA08503; Thu, 17 Apr 2003 04:29:30 +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 EAA08644 for ; Thu, 17 Apr 2003 04:29:28 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h3H2TQ901650 for ; Thu, 17 Apr 2003 04:29:27 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2/3.7W) with ESMTP id LAA09497; Thu, 17 Apr 2003 11:29:19 +0900 (JST) To: A.Simon@ukc.ac.uk Cc: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic modules in classes In-Reply-To: <20030415111241.GB20789@myrtle.ukc.ac.uk> References: <20030415111241.GB20789@myrtle.ukc.ac.uk> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030417112920P.garrigue@kurims.kyoto-u.ac.jp> Date: Thu, 17 Apr 2003 11:29:20 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Spam: no; 0.00; jacques:01 caml-list:01 hashtbl:01 functor:01 struct:01 hash:01 outch:01 bin:01 workaround:01 sig:01 int:01 garrigue:01 polymorphic:01 simpler:01 compile:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Axel Simon > When I compile, I get "Unbound type constructor a'" for the line which > introduces stored, although it works with int. This just looks like a typo: this should be 'a (a type variable), not a' (an identifier). When fixed, your program is accepted. > I guess there are many > other problems with my solution: PhysEq.t is abstract and PhysHashtbl.key > is not bound to any type. How do I solve all this? This one is a much more serious problem, and appears frequently on this list. The only solution currently is to copy the Hashtbl module, replacing key by 'a key, and 'a t by ('b,'a) t. A simpler workaround is to define a functor producing your class. module Make(T : sig type t end) = struct module PhysEq = struct type t = T.t let equal = (==) let hash = H.hash end module PhysHashtbl : H.S with type key = T.t = H.Make(PhysEq) class ['a] bulkWriter ((fname, wr) : string * (out_channel -> 'a -> unit)) = let outCh = open_out_bin fname and stored : ('a PhysHashtbl.t) = (PhysHashtbl.create 100) in object (* something here *) end end Then you can create a class for every type you need. But I'm not sure exactly of what you intend to use your hash table for. Does it really need to handle many types? Jacques Garrigue ------------------- 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