Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] how to use functors?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <christophe.raffalli@u...>
Subject: Re: [Caml-list] how to use functors?
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
---------------------------------------------