From: Berke Durak <berke.durak@exalead.com>
Cc: Caml-list List <caml-list@inria.fr>
Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons
Date: Tue, 26 Feb 2008 14:10:13 +0100 [thread overview]
Message-ID: <47C40FB5.1090603@exalead.com> (raw)
In-Reply-To: <47C3F96E.4080901@exalead.com>
I have found a where, for each category C (such as place or person), you add a method
as_C : C
in physical that throws a Class_cast_exception, and override it with a method that returns
self in class C. However this means that the type C must appear in the definition of physical,
which means that either
(a) All categories C1, ..., Cn are defined in the same file in the same bunch
of mutually-recursive class definitions; a solution evidently not scalable.
(b) The physical class is parametrized by n paramters 'C1, 'C2, ... 'Cn, which
must be repeated everywhere.
The latter solution works for small n but the complexity of incremental maintenance is in O(n).
This means that if you define your n classes in n files, you'll have to edit n files to add
an (n+1)-th class.
This leads me back to an idea I was talking about with Yann Régis-Gianas a few months ago :
the ability to bundle type parameters as a named record and to access their components.
You could write, in a file
f.ml:
type ''bundle := ('place, 'person, 'c3, 'c4 ...)
then in physical.ml :
class [F.''bundle] physical =
object
method as_place : raise Class_cast_exception
method as_person : raise Class_cast_exception
method as_c3 : raise Class_cast_exception
end
and in place.ml
class [F.''bundle] place =
object(self : 'a)
constraint ''bundle.'place = 'a
method as_place = self
end
and so on... I don't know how much sense this makes with respect to separate compilation.
However, this would allow you to add a category by just editing two files.
--
Berke DURAK
next prev parent reply other threads:[~2008-02-26 13:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-26 11:35 Berke Durak
2008-02-26 12:14 ` [Caml-list] " Richard Jones
2008-02-26 14:28 ` Berke Durak
2008-02-26 14:48 ` Richard Jones
2008-02-26 14:59 ` Berke Durak
2008-02-27 13:26 ` Tiphaine.Turpin
2008-02-29 10:36 ` Berke Durak
2008-02-29 12:23 ` Tiphaine.Turpin
2008-02-26 12:48 ` ketti
2008-02-26 13:10 ` Berke Durak [this message]
2008-02-26 15:07 ` Dirk Thierbach
2008-02-26 16:25 ` Berke Durak
2008-02-27 7:37 ` Dirk Thierbach
2008-02-27 10:26 ` Berke Durak
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=47C40FB5.1090603@exalead.com \
--to=berke.durak@exalead.com \
--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