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 E746FBC69 for ; Wed, 15 Aug 2007 03:30:24 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7F1UMg6012155 for ; Wed, 15 Aug 2007 03:30:23 +0200 X-IronPort-AV: E=Sophos;i="4.19,262,1183300200"; d="scan'208";a="172769487" Received: from ppp121-44-98-105.lns10.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.98.105]) by ipmail01.adl2.internode.on.net with ESMTP; 15 Aug 2007 10:58:36 +0930 Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object From: skaller To: Jon Harrop Cc: caml-list@yquem.inria.fr In-Reply-To: <200708142144.15414.jon@ffconsultancy.com> References: <20070814101535.GA14485@furbychan.cocan.org> <46C18D1B.2070303@functionality.de> <200708142144.15414.jon@ffconsultancy.com> Content-Type: text/plain Date: Wed, 15 Aug 2007 11:28:35 +1000 Message-Id: <1187141315.6101.22.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 46C2572E.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 nodes:01 hashtbl:01 compiler:01 variants:01 compilation:01 mutable:01 abstraction:01 sourceforge:01 On Tue, 2007-08-14 at 21:44 +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 not a precise description. You cannot put arbitrary meta-data into the Seq nodes with this design, for a given data structure, you can choose just one type of meta-data: this is the same as for example a Hashtbl. If you wish to *dynamically* vary the meta data, which is often the case when you have a tool like a compiler that performs phased analysis, a property list based on polymorphic variants can be useful. This is one of three ways I can think of to vary the data type dynamically across compilation unit boundaries. A second way is to use mutable field of a class type and change the object to a different implementation of the same abstraction. The third way is quite tricky and equivalent to the first: use a function unit -> unit as the type, and execute it to throw an exception. This is basically dynamic typing. -- John Skaller Felix, successor to C++: http://felix.sf.net