caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: Jonathan Roewen <jonathan.roewen@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] how to use functors?
Date: Tue, 22 Nov 2005 16:22:51 +0100	[thread overview]
Message-ID: <438337CB.5070105@univ-savoie.fr> (raw)
In-Reply-To: <ad8cfe7e0511191337q4de3366cuaa1ca62be993f56b@mail.gmail.com>

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
---------------------------------------------


      parent reply	other threads:[~2005-11-22 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-19 21:37 Jonathan Roewen
2005-11-19 22:11 ` Jon Harrop
2005-11-22 15:22 ` Christophe Raffalli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=438337CB.5070105@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=jonathan.roewen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).