From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA16085 for caml-redistribution; Fri, 4 Apr 1997 19:04:44 +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 NAA11134 for ; Fri, 4 Apr 1997 13:43:20 +0200 (MET DST) Received: from nenuphar.saclay.cea.fr (nenuphar.saclay.cea.fr [132.166.192.7]) by nez-perce.inria.fr (8.7.6/8.7.3) with SMTP id NAA18350 for ; Fri, 4 Apr 1997 13:43:19 +0200 (MET DST) Received: from soleil.serma.cea.fr by nenuphar.saclay.cea.fr (8.6.9/ CEANET-ROUTER-3.0) with ESMTP id NAA17979 for ; Fri, 4 Apr 1997 13:43:16 +0200 Received: (from basile@localhost) by soleil.serma.cea.fr (8.8.5/8.8.0) id NAA11665; Fri, 4 Apr 1997 13:44:43 +0200 Date: Fri, 4 Apr 1997 13:44:43 +0200 Message-Id: <199704041144.NAA11665@soleil.serma.cea.fr> From: Basile STARYNKEVITCH MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: caml-list@inria.fr Subject: Q: hashtables of parametrized types in Ocaml? X-Mailer: VM 6.22 under 19.15 XEmacs Lucid Sender: weis Hello [[English]] Suppose I have (* a symbol has a name and a value; value type is unspecified here; in practice it will be defined in another module! *) type 'a asymbol_t = { sy_name: string; sy_val: 'a } (* the hash of a symbol is the hash of its name *) let symhash { sy_name= name } = Hash.hash name; Now I would like to define hashtable of symbol thru the Hashtbl.Make functor. I tried module SymbolHashtbl = Hashtbl.Make(struct type t = 'a asymbol_t let equal = (==) let hash = symhash end) but it doesn't work! How can I achieve an equivalent result? Of course I would like the resulting symbol hashtable module to have a key type parametrized by 'a (symbols' value type) and a table type parametrized by 'a (the same symbols' value type) and by 'b (the arbitrary hash value type - noted 'a on section 16.10 page 186 of refman1.05) The reason of all this is that I have in my application (some kind of translator, building and working on program abstract syntax trees) symbols and tree nodes - each node has a symbol and may have subnodes. A symbol may have as value a tree node. So I have a module Symbol (defining type 'a asymbol_t) and another module Abstree (for abstract syntax trees) defining type node_t and symbol_t = node_t asymbol_t. Perhaps a double functor is the answer, but I can't figure it out! [[French summary]] Comment créer une table de hash (via Hashtbl) de types parametrés. Mon type asymbol_t (defini ci-dessus) est parametré par le type 'a des valeurs de symbole (instantié dans un autre module). Mais le hashage ne porte que sur le nom du symbole. Comment faire une table de hash sur ces symboles. N.B. Any opinions expressed here are solely 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 DRN/DMT/SERMA * CEA/Saclay bat.470 * 91191 GIF/YVETTE CEDEX * France fax: (33) 01,69.08.85.68; phone: 01,69.08.40.66; home: 01,46.65.45.53 email: Basile . Starynkevitch @ cea . fr (but remove white space) I speak french, english, russian. Je parle français, anglais, russe. ----------------------------------------------------------------------