From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: tews@irritatie.cs.kun.nl (Hendrik Tews)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: subtyping and inheritance
Date: Mon, 25 Jan 1999 01:08:30 +0100 (MET) [thread overview]
Message-ID: <199901250008.BAA29432@miss.wu-wien.ac.at> (raw)
In-Reply-To: <199901201150.MAA09911@irritatie.cs.kun.nl> from "Hendrik Tews" at Jan 20, 99 12:50:21 pm
Hello,
> This is true. But what you really need to solve your problem is a
> feature called sometimes "(covariant) specialization of code".
> Ocaml does not have this feature. Therefore you can not hope for
> a solution which is typesafe and supports code reuse. Ocaml does
> provide the feature "contravariant subtyping", which gives you a
> save subtype relation. There is nice paper of Guiseppe Castagna
> "Covariance and Contravariance: Conflict without a Cause" [1]
> which discusses those features and their relation.
>
> This paper and the references therein contain also proposals how
> to integrate specialization of code into a record based object
> oriented language. Is their any hope, that ocaml adopts this (or
> any other) solution in the future, such that Markus can implement
> comparison of terminals and symbols in a clean way?
> [1] G. Castagna. Covariance and contravariance: conflict without
> a cause. ACM Transactions on Programming Languages and Systems
> 17(3):431-447, March 1995. Also available at
> http://www.ens.fr/~castagna/pub.html.
I have taken a close look on the paper now. As it seems, it exactly
addresses the problem I (and probably many others) have. Quotes with
[remarks]:
... Despite its unsoundness, covariant specialization has its tenacious
defenders, and not without cause. [snip] The contravariant rule,
besides being less intuitive than the covariant one, is the source of
many problems. The most surprising one appears with binary methods
and can be exemplefied as follows. [snip details of the problem I
actually have]. This is quite unintuitive [yes, I think so, too]
[snip]. Furthermore, experience with O2 (which is the third most
sold object-oriented database management system in the world) shows,
that the unsoundness of the type-checker has not caused many problems
in practice.
So far it seems that things would be unsafe with covariance. But now,
Castagna answers my (former) question, whether making "reappear" methods
from ancestors would be safe: it is...
The paper looked difficult at first, but turned out to be surprisingly
easy to read: Castagna makes the theorie very intuitively clear with his
examples of classes "2DPoint" and "3DPoint" and how methods are chosen
in the different models.
The record based method (as found in OCAML - the object (record)
determines, which method is selected, arguments are not considered)
can be obviously extended to support covariance.
Sylvain Boulmé pointed out that semantics could become difficult to
understand. I am not sure whether this would really turn out to be a
problem. Implementing a large project employing a deep class hierarchie
in both approaches could probably demonstrate, where their strengths
and weaknesses are. But at the moment, we don't have this choice...
> There was already a proposal how to solve the problem by Jerome
> Vouillon. Just for demonstration I append another solution, which
> uses a self implemented type case. It supports code reuse better,
> but loses type security by using the Obj module. Maybe one of the
> people who "understand the whole source code for the O'Caml
> compiler, runtime and libraries" and by that can use the Obj
> module, can comment on its use here.
[snip code]
Nice example code! I don't know what "Obj.magic" does internally,
but I believe it can do real black (= unintended) magic, too. Thus,
it is certainly not advisable to use it as a surrogate for the missing
feature of covariance. But Hendrik's intention is surely to demonstrate,
how objects could behave in such an environment...
Best regards,
Markus
--
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
next prev parent reply other threads:[~1999-01-25 8:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-11 18:52 Markus Mottl
1999-01-15 15:02 ` Jerome Vouillon
1999-01-15 17:37 ` Markus Mottl
1999-01-18 19:55 ` Jerome Vouillon
1999-01-18 21:18 ` Markus Mottl
1999-01-20 11:50 ` Hendrik Tews
1999-01-25 0:08 ` Markus Mottl [this message]
1999-01-25 15:06 ` Musings on Obj.magic (Was: subtyping and inheritance) David Monniaux
1999-01-27 14:18 ` subtyping and inheritance Jerome Vouillon
1999-01-27 14:45 ` Markus Mottl
1999-01-28 19:40 ` Hendrik Tews
1999-01-27 14:28 ` Jerome Vouillon
1999-04-15 12:18 Giuseppe Castagna
1999-04-15 16:02 ` Markus Mottl
1999-04-20 12:38 ` Didier Remy
1999-04-20 15:06 ` Giuseppe Castagna
1999-04-21 12:18 ` Didier Remy
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=199901250008.BAA29432@miss.wu-wien.ac.at \
--to=mottl@miss.wu-wien.ac.at \
--cc=caml-list@inria.fr \
--cc=tews@irritatie.cs.kun.nl \
/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