comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: tagged record child: override constructor?
Date: Fri, 16 Sep 2005 23:03:30 +0200
Date: 2005-09-16T23:02:26+02:00	[thread overview]
Message-ID: <93g4w5iedrdj.qjv8pbklcryx$.dlg@40tude.net> (raw)
In-Reply-To: 1126882356.112798.288440@g14g2000cwa.googlegroups.com

On 16 Sep 2005 07:52:36 -0700, Hyman Rosen wrote:

> I still think
> that Ada's requirement that tagged types be passed by reference
> shows that it was a mistake for the language to try to conceal
> the parameter passing mode from the programmer.

Why do you think so? The program semantics should be independent from the
parameter passing mode. The type identity is another thing. Though IMO, it
is always suspicious from the design point view to have objects with
identity. Fortunately Ada does not re-dispatch by default. I say
fortunately, because it was a number of times were the compiler gave me the
message, that a class-wide was expected, but a specific type was found
instead. I can remember none of them, where the program were right. In C++
these errors would slip through.

>> But the actual parameter may have another type. It leaks!
> 
> Irrelevant. When the paramater is of a specific class type
> and you pass a derived type as an argument, the parameter
> simply receives a copy of the base part of the argument.
> It's referred to as "slicing". And just as you claim to prefer,
> once that happens there is no going back to the derived type.
> The parameter is well and truly only of its declared type.

But it is not a copy of the actual object. It is a copy of its part! The
point is that T and T& are no less different C++ than T and T'Class in Ada.
But in C++ T& is overloaded with two different meanings: closure of types
(class) vs. reference type. As a consequence T& is always a reference to
class (except from con/destructors (:-)) You cannot have a reference to a
specific type. Same with pointers. In Ada both renaming (a rough equivalent
of reference) and access types can be either specific or class-wide. Wasn't
Java's final types an unsuccessful attempt to mend this? Further, because
T& is not an object, you cannot do such elementary thing as to copy a
polymorphic object.

>> "A type is characterized by a set of values..."
> 
> But what is the set of values for a tagged type?
> Doesn't it include the values of all possible derived types?

No. It is the class rooted in the type which do. A T'Class serves as a
closure of all types derived from T.

> After all, reading 4.6, it certainly seems that I'm allowed
> to do view conversions back and forth between base and derived
> tagged types.

A view conversion is still a conversion. If all types had classes, then for
non-tagged types T<->T'Class were a full conversions constructing new
objects.

In Ada there are things much close to this pattern. Unconstrained array
types are similar to classes, their constrained subtypes are similar to
specific types. Here bounds play the same role as the tag does. Note that
the language does not define how bounds are passed back and forth. It also
allows to pass arrays by copy and throw known bounds away.

>> There is a great difference between not yet implemented things and ones
>> which cannot be under any circumstances.
> 
> The requirements for view conversion and by-refernce passing
> make it seem to me that no Ada compiler will ever implement
> your version of things.

This is required for tagged types only.

Let's wait until people finally turn sick of templates! (:-))

>> The argument "this" is first converted from B* to A*, then this->A::g() is
>> called, then it is converted back to B*.
> 
> And when this->A::g() calls f(), it does so by dispatching, regardless
> of whether the A::g() call originated in a constructor or not.

Don't you see that the following two interpretations are equivalent:

1. It dispatches, but the tag changes

2. It does not dispatch, and the tag is constant.

It is clear that you prefer (1) because your mental model is many types -
one object. But I stick to (2) because I am convinced that the multiple
types model will show itself infeasible, should somebody try to formalize
it.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2005-09-16 21:03 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-13  5:58 tagged record child: override constructor? sean.gilbertson
2005-09-13  6:39 ` David Trudgett
2005-09-13  7:32 ` Dmitry A. Kazakov
2005-09-13  7:56   ` tmoran
2005-09-13 15:23   ` sean.gilbertson
2005-09-13 17:37     ` Martin Krischik
2005-09-13 19:29       ` Ludovic Brenta
2005-09-14  7:49         ` Dmitry A. Kazakov
2005-09-14  9:05           ` Maciej Sobczak
2005-09-14 13:20             ` Dmitry A. Kazakov
2005-09-14 13:52               ` Hyman Rosen
2005-09-14 16:47                 ` Dmitry A. Kazakov
2005-09-14 17:16                   ` Hyman Rosen
2005-09-14 20:20                     ` Dmitry A. Kazakov
2005-09-14 20:34                       ` Georg Bauhaus
2005-09-14 20:56                       ` Hyman Rosen
2005-09-15  7:31                         ` Dmitry A. Kazakov
2005-09-15 13:19                           ` Hyman Rosen
2005-09-15 13:45                             ` Maciej Sobczak
2005-09-15 17:45                             ` Dmitry A. Kazakov
2005-09-15 18:54                               ` Hyman Rosen
2005-09-16  9:32                                 ` Dmitry A. Kazakov
2005-09-16 14:52                                   ` Hyman Rosen
2005-09-16 15:33                                     ` Jean-Pierre Rosen
2005-09-16 18:37                                       ` Hyman Rosen
2005-09-16 21:03                                     ` Dmitry A. Kazakov [this message]
2005-09-16 21:33                                       ` Hyman Rosen
     [not found]                                         ` <98ox2x9xvj9z.1uh92dslhvt4g.dlg@40tude.net>
2005-09-17 12:47                                           ` Georg Bauhaus
2005-09-17 15:56                                             ` Dmitry A. Kazakov
2005-09-14 16:14           ` Martin Krischik
2005-09-14 16:57             ` Dmitry A. Kazakov
2005-09-14 18:35               ` Martin Krischik
2005-09-14  9:28         ` Alex R. Mosteo
2005-09-14 16:10         ` Martin Krischik
2005-09-13  9:33 ` Georg Bauhaus
2005-09-13 16:37 ` Jeffrey Carter
2005-09-13 18:55   ` Robert A Duff
2005-09-13 22:18     ` Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox