From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id DAA07102 for caml-redistribution; Thu, 8 Jul 1999 03:50:18 +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 MAA28948 for ; Mon, 5 Jul 1999 12:57:15 +0200 (MET DST) Received: from nenuphar.saclay.cea.fr (nenuphar.saclay.cea.fr [132.166.192.7]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id MAA04062 for ; Mon, 5 Jul 1999 12:57:14 +0200 (MET DST) Received: from muguet.saclay.cea.fr (muguet.saclay.cea.fr [132.166.192.6]) by nenuphar.saclay.cea.fr (8.9.1a/8.9.1/CEAnet-relay-5.0.D20) with ESMTP id MAA27577 for ; Mon, 5 Jul 1999 12:57:13 +0200 (MET DST) Received: from harpie.saclay.cea.fr (harpie.saclay.cea.fr [132.166.133.152]) by muguet.saclay.cea.fr (8.9.1a/8.9.1/CEAnet-relay-5.0.D20) with ESMTP id MAA17466; Mon, 5 Jul 1999 12:57:12 +0200 (MET DST) Received: by harpie.saclay.cea.fr (8.8.8+Sun/CEANET.2.0.1) id MAA04036; Mon, 5 Jul 1999 12:57:08 +0200 (MET DST) From: STARYNKEVITCH Basile MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Message-ID: <14208.36740.406400.710367@gargle.gargle.HOWL> Date: Mon, 5 Jul 1999 12:57:08 +0200 (MET DST) To: caml-list@inria.fr Subject: Q: parametric types in simple functors? X-Mailer: VM 6.72 under Emacs 20.3.1 Content-Transfer-Encoding: 8bit Content-Transfer-Encoding: 8bit Sender: weis The subject title is poor. I have a concrete simple question. (All CAML code is indented to the right here) Consider type 'a symbol = { sy_name: string; sy_hash: int; mutable sy_prop: 'a option };; This is essentially a symbol, memoizing its hash code for fast access. Some structures are naturally hashed map, whose key are symbols (eg bindings). We make symbols with let get_symbol n = try Hashtbl.find symdict n with Not_found -> let s = { sy_name=n; sy_hash=Hashtbl.hash n; sy_prop=None } in Hashtbl.add symdict n s; s ;; The property field of symbols could be used the way you like it. I want to define a binding as an hashtable mapping symbols to (say) integers - or even any type 'b. But I can't code: module SymbolHash = Hashtbl.Make( struct type t = symbol let equal s1 s2 = s1 == s2 let hash {sy_hash=h} = h end) ;; Because the type constructor t has no argument in the Hashtbl.HashedType signature. Any comments or suggestions (could define a class abstract_symbol with a subclass symbol holding the properties. But I don't want classes because I don't need inheritance). The intent is that the symbol properties would be defined in another module. I don't want to fix the 'a in symbol_t here, yet I want to make an hashtable whose keys are symbols. In other words, why the stdlib doesn't give parametrized types for many modules (Hashtbl, Set...) when should I use a type constructor with an argument, or a functor? Any comments? N.B. Any opinions expressed here are only mine, and not of my organization. N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA. --------------------------------------------------------------------- Basile STARYNKEVITCH ---- Commissariat à l Energie Atomique DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53 email: Basile point Starynkevitch at cea point fr