From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 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 D3B1CBC69 for ; Wed, 15 Aug 2007 21:04:56 +0200 (CEST) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7FJ4uit020840 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 15 Aug 2007 21:04:56 +0200 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1ILOAp-00028G-00 for ; Wed, 15 Aug 2007 20:04:55 +0100 Date: Wed, 15 Aug 2007 20:04:55 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object Message-ID: <20070815190455.GA4568@furbychan.cocan.org> References: <20070814101535.GA14485@furbychan.cocan.org> <46C18D1B.2070303@functionality.de> <200708142144.15414.jon@ffconsultancy.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200708142144.15414.jon@ffconsultancy.com> User-Agent: Mutt/1.5.9i From: Richard Jones X-Miltered: at concorde with ID 46C34E58.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; hash:01 0100,:01 expr:01 seq:01 seq:01 expr:01 nodes:01 pxp:01 nodes:01 transforming:01 annotations:01 variants:01 node:01 statically:01 hash:01 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 & 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