caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object
Date: Wed, 15 Aug 2007 20:04:55 +0100	[thread overview]
Message-ID: <20070815190455.GA4568@furbychan.cocan.org> (raw)
In-Reply-To: <200708142144.15414.jon@ffconsultancy.com>

On Tue, Aug 14, 2007 at 09:44:15PM +0100, Jon Harrop wrote:
> You can also parameterize the type over metadata:
> 
>   type 'a expr =
>     | Int of int
>     | Var of string
>     | Seq of 'a seq
>   and 'a seq = {h: 'a expr; t: 'a expr array; meta: 'a};;
> 
> Now you can insert arbitrary metadata into Seq nodes.

This is basically what PXP does, and what my own PG'OCaml does.
Unfortunately it's not very usable for a few practical reasons, as I
shall describe.

Firstly it only allows a single annotation.  You can use a tuple to
get around that, but that requires the annotators to cooperate
somehow, which is not much good if you're combining code from several
places.

Secondly if you don't want to annotate, you need to manually cast the
type to 'unit t' somewhere in your main program (and that will fail if
one of the libraries you're using wants to annotate the type).

Also, can you safely annotate the nodes one way in one part of your
program, and other way in another part (eg. if you're transforming a
tree with annotations, in stages)?  Using variants isn't completely
safe (but then neither are WHTs in this instance because you can not
annotate a node and WHTs don't catch this statically).

> If your metadata are sporadically used or, in particular, only sparsely 
> present or you do not have access to the library then the weak hash table 
> approach is probably the way to go.

I should have said :-) I'm trying to annotate the <img> & <applet>
nodes in a typical HTML document, so they are both sparse (compared to
all nodes), but there are many of them.

Rich.

-- 
Richard Jones
Red Hat


  parent reply	other threads:[~2007-08-15 19:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-14 10:15 Richard Jones
2007-08-14 11:08 ` [Caml-list] " Thomas Fischbacher
2007-08-14 11:48   ` Till Varoquaux
2007-08-14 20:44   ` Jon Harrop
2007-08-14 23:09     ` Stefano Zacchiroli
2007-08-15  0:33       ` Jon Harrop
2007-08-15 12:33         ` Daniel Bünzli
2007-08-16 14:54         ` Markus Mottl
2007-08-15  1:28     ` skaller
2007-08-15 19:04     ` Richard Jones [this message]
2007-08-16 16:17       ` Some observations and measurements with using Weak Hashtable to annotate a tree (was: Re: [Caml-list] Weak hash table for attaching extra data to an object) Richard Jones
2007-08-14 16:22 ` [Caml-list] Weak hash table for attaching extra data to an object Richard Jones
2007-08-14 23:24   ` Till Varoquaux
2007-08-14 23:35   ` Fernando Alegre
2007-08-15  7:59     ` Richard Jones

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=20070815190455.GA4568@furbychan.cocan.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    /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).