comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Limited_Controlled, orthogonality and related issues
Date: 18 Jan 2007 09:02:24 -0800
Date: 2007-01-18T09:02:24-08:00	[thread overview]
Message-ID: <1169139744.717060.69070@51g2000cwl.googlegroups.com> (raw)
In-Reply-To: eoned5$663$1@cernne03.cern.ch

Maciej Sobczak wrote:
> Hi,
>
> Consider the following problem:
>
> package P is
>     type T is limited private;
>     type S is limited private;
>     procedure Do_The_Job(X : in T; Y : in S);
>     -- and gazillion of other subprograms like Do_The_Job
> private
>     -- ...
> end P;
>
> At some point I decide to add automatic destruction to T and S, so the
> package becomes:
>
> with Ada.Finalization;
> package P is
>     type T is limited private;
>     type S is limited private;
>     procedure Do_The_Job(X : in T; Y : in S);
>     -- and gazillion of other subprograms like Do_The_Job
> private
>     type T is new Ada.Finalization.Limited_Controlled with -- ...
>     type S is new Ada.Finalization.Limited_Controlled with -- ...
> end P;
>
> Suddenly, the package no longer compiles:
>
> "operation can be dispatching in only one type"
>
> By making T and S controlled types, they became tagged and Do_The_Job is
> now incorrect.

On looking at this, I wonder if this was an error in the design of Ada
95.  Primitive operations of tagged types are dispatching, and the
reason is that so that another package can declare a type extension
from a tagged type and inherit the dispatching operation, and possibly
override it, and then somebody could use the operation on a class-wide
type to call the correct operation for that particular object, and thus
achieve polymorphism.  But when  the partial view of a type is not
tagged, then other packages can't derive type extensions from it and
can't apply 'Class to it, so was there any logical reason why an
operation on that type (declared in the visible part of the package)
should be dispatching?  Maybe not, since the dispatch could "almost
never" take place in practice, and since making the operation
dispatching adds restrictions just like the one Maciej found.

I say "almost never" because in theory, since the private part or body
of P or of a child of P (or the visible part of a private child of P)
*could* derive a type extension from the tagged type and dispatch.  But
I'd guess that such usage would be rare.

So it seems to me that (1) it would have been better to say in 3.9.2
that a primitive operation of an untagged private type whose full view
is tagged is not dispatching, at least if the operation is declared in
the visible part of the package; or (2) some way should have been
provided for the programmer to specify that an operation that 3.9.2
defines as "dispatching" really isn't.

Maybe (2) is still possible.  I'm guessing that it's way too late to
make (1) the rule.  So this is probably really just a useless rant.

Has this issue been discussed somewhere else, by the way?

                           -- Adam




  parent reply	other threads:[~2007-01-18 17:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-18  9:24 Limited_Controlled, orthogonality and related issues Maciej Sobczak
2007-01-18 12:00 ` Ludovic Brenta
2007-01-18 12:33   ` AW: " Grein, Christoph (Fa. ESG)
2007-01-18 16:25   ` Robert A Duff
2007-01-18 17:02 ` Adam Beneschan [this message]
2007-01-18 17:16   ` Adam Beneschan
2007-01-19  1:02     ` Robert A Duff
2007-01-19  7:38       ` Maciej Sobczak
2007-01-19  9:05     ` Dmitry A. Kazakov
2007-01-19 17:04       ` Adam Beneschan
2007-01-19  1:01   ` Robert A Duff
2007-01-19  9:57   ` Stephen Leake
2007-01-18 19:03 ` Jeffrey Carter
2007-01-19  7:48 ` Randy Brukardt
2007-01-19 16:46   ` Adam Beneschan
2007-01-19 15:29 ` Robert A Duff
2007-01-19 16:31   ` Dmitry A. Kazakov
2007-01-19 16:36     ` Robert A Duff
2007-01-19 18:26       ` Dmitry A. Kazakov
2007-01-19 20:17         ` Robert A Duff
2007-01-20 10:14           ` Dmitry A. Kazakov
2007-01-20 14:44             ` Robert A Duff
replies disabled

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