From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 02122BB9C for ; Tue, 22 Nov 2005 16:22:55 +0100 (CET) Received: from net.univ-savoie.fr (net.univ-savoie.fr [193.48.120.75]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAMFMs47002443 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 22 Nov 2005 16:22:54 +0100 Received: from post.bourget.univ-savoie.fr (post.bourget.univ-savoie.fr [193.48.120.73]) by net.univ-savoie.fr (8.12.3/jtpda-5.4) with ESMTP id jAMFMnJF027360 ; Tue, 22 Nov 2005 16:22:49 +0100 Received: from [193.48.123.45] (d45.lama.univ-savoie.fr [193.48.123.45]) by post.bourget.univ-savoie.fr (8.12.3/jtpda-5.4) with ESMTP id jAMFMjKE021714 ; Tue, 22 Nov 2005 16:22:45 +0100 Message-ID: <438337CB.5070105@univ-savoie.fr> Date: Tue, 22 Nov 2005 16:22:51 +0100 From: Christophe Raffalli User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: fr, en MIME-Version: 1.0 To: Jonathan Roewen Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] how to use functors? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) X-Miltered: at concorde with ID 438337CE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 caml-list:01 functors:01 functor:01 hashtable:01 hashtbl:01 trivial:01 functor:01 hashtable:01 hash:01 hashtbl:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Jonathan Roewen a écrit : > Hi, > > Prolly the wrong list, but I can't access caml.inria.fr's documentation ATM =/ > > How do I use a functor? For example: build a weak hashtable from Weak > module? Seems useful for building a cache... if only I knew how to use > it =P > > Jonathan > You want weak key, weak vailue or both ? I mean you want the binding in the hashtbl to disappear when the key is no more GC accessible, the value of both ? Let us assume you want key-weak ... This is not completely trivial to do what you want from the Weak module and this is not a problem of functor ... A way to do that is to do build a weak array for the key, with a hashtable algorithm for the index (the position of the key in the array depends upon the hash function) Then you put the associated value in a separate non weak array, at the same index than the key. Finaly, you also put a finaliser on the key to erase the associated value when the key is collected by the GC ... I hope this help ... and I think weak hashtbl should be provided by the language ... -- Christophe Raffalli Université de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tél: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI --------------------------------------------- IMPORTANT: this mail is signed using PGP/MIME At least Enigmail/Mozilla, mutt or evolution can check this signature. The public key is stored on www.keyserver.net ---------------------------------------------