Browse thread
Weak hash table for attaching extra data to an object
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | skaller <skaller@u...> |
| Subject: | Re: [Caml-list] Weak hash table for attaching extra data to an object |
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 <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net