caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: "Johan Baltié" <johan.baltie@wanadoo.fr>, Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Recovering masked methods (with CamlP4?)
Date: Tue, 16 Jul 2002 14:52:23 +0200	[thread overview]
Message-ID: <3D341707.8020606@baretta.com> (raw)
In-Reply-To: <20020716113240.M56995@wanadoo.fr>



Johan Baltié wrote:

> Uhh ? I have missed something. Can you forward me this post privately ? I cannot
> find it. It seems awful to me to hear that inheritance is "syntactic", because
> it does mean (for me) that nothing happen at runtime.
> 

I've been looking for the exact post, but I can't find it. I 
remember distictly to have read something like that a little 
while ago, yet I cannot find the message.

Anyhow, insofar as I have understood the workings of the 
Ojbective part of the Caml, class inheritance is merely 
supposed to be a form of type safe code reuse (something of 
a macroexpansion to use C/++ terminology). In C++, if class 
B inherits from class A, B *is an* A. In O'Caml this is not 
true. B has all the functionality (read, "methods") provided 
by A. Nowhere is it guaranteed to be either type-equivalent 
to or a subtype of A. Therefore, an instance of B cannot be 
used wherever an instance of A can be used. And even if B 
*is a subtype* of A, then instances of B must be explicitly 
coerced to having type A (this amounts to method hiding, 
AFAIK) before they can be used as actual parameters to 
funtions whose formal parameter is of type A.

An example of this feature is Pxp's parse_document entity 
function. In order to check che validity of the use of ID 
and IDREF attribute fields in an XML document, the above 
function must be passed an object of type index = < 
{some_methods} >. But this is only a class type (an 
interface à la Java). Gerd Stolpmann provides an 
implementation class hash_index which is a sub_type of of 
index (implements the interface), but adds one extra method. 
In order to pass an object instance of hash_index to 
parse_document_entity you have to explicitly coerce it to 
having type index.

This is why it is perfectly sensible to let class 
variant_of_b inherit from class b, although the two classes 
*are not* in an "is a" relation with one another. You get 
the benefit of inheriting all the code in b which is also 
needed in variant_of_b, all the while retaining the 
possibility of adding methods to variant_of_b such that 
variant_of_b *is not a* b.

This approach to inheritance is radically different from 
that of C++. It takes a while to get the hang of it. It's 
actually much more powerful.

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-07-16 12:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15 23:13 [Caml-list] Recovering masked methods Alessandro Baretta
2002-07-16  1:15 ` Jacques Garrigue
2002-07-16  9:28   ` Alessandro Baretta
2002-07-16  9:48     ` Laurent Vibert
2002-07-16 10:08       ` Johan Baltié
2002-07-16 10:10       ` Alessandro Baretta
2002-07-16  9:59     ` Johan Baltié
2002-07-16 11:08       ` [Caml-list] Recovering masked methods (with CamlP4?) Alessandro Baretta
2002-07-16 11:32         ` Johan Baltié
2002-07-16 12:52           ` Alessandro Baretta [this message]
2002-07-16 12:26         ` Daniel de Rauglaudre
2002-07-16 12:54           ` Alessandro Baretta
2002-07-17  9:26             ` Daniel de Rauglaudre
2002-07-16 13:32         ` John Prevost
2002-07-16 13:35           ` John Prevost
2002-07-16 14:06           ` Alessandro Baretta
2002-07-16 14:15             ` Johan Baltié
2002-07-16 14:29               ` Alessandro Baretta
2002-11-11  9:20         ` Eray Ozkural
2002-07-16 10:45     ` [Caml-list] Recovering masked methods John Prevost

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=3D341707.8020606@baretta.com \
    --to=alex@baretta.com \
    --cc=caml-list@inria.fr \
    --cc=johan.baltie@wanadoo.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;
as well as URLs for NNTP newsgroup(s).