From: skaller <skaller@users.sourceforge.net>
To: Jon Harrop <jon@ffconsultancy.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object
Date: Wed, 15 Aug 2007 11:28:35 +1000 [thread overview]
Message-ID: <1187141315.6101.22.camel@rosella.wigram> (raw)
In-Reply-To: <200708142144.15414.jon@ffconsultancy.com>
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
next prev parent reply other threads:[~2007-08-15 1:30 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 [this message]
2007-08-15 19:04 ` Richard Jones
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=1187141315.6101.22.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@yquem.inria.fr \
--cc=jon@ffconsultancy.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).