comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Why constructing functions is a mess [was Language lawyer question: task activation
Date: Sat, 28 Feb 2009 14:45:29 +0100
Date: 2009-02-28T14:45:32+01:00	[thread overview]
Message-ID: <1wzjy9pzbft1m.1lut7nszfkzmp$.dlg@40tude.net> (raw)
In-Reply-To: 49a92c29$0$32670$9b4e6d93@newsspool2.arcor-online.net

On Sat, 28 Feb 2009 13:20:51 +0100, Georg Bauhaus wrote:

> Dmitry A. Kazakov wrote:
> 
>> Topic: large system design, information hiding:
>> 
>>       type T (<>) is abstract tagged limited private;
>>    private
>>       type T (...constraints...) is abstract tagged limited record
>>          ...
>>       end record;
>> 
>> In order to be used in
>> 
>>    type S is new T with ...;
>>    function Create (....) return S;
> 
> How/Why should this derivation be possible?

Because it is so in Ada (the discriminants are inherited).

The idea of <> introduced in Ada 95 was to be able to hide the
discriminants. The idea of Pickwickian function was in part to overcome Ada
design bug that the discriminants can be hidden but not abstracted.

Note that if T weren't abstract, a Pickwickian function would work:

   type T (<>) is tagged limited private;
   function Create (...parameters...) return T;
private
   type T (...constraints...) is tagged limited record ..

Observe, that this abstracts the discriminants of T, which in the public
part are represented by the arguments of Create. Now the arguments of
Create are kind of "public discriminants." The private discriminants are of
nobody's interest.

Another Pickwickian construct is limited aggregate in which you can use a
Pickwickian call to the Pickwickian function Create and this incredible
combination gives us an ability to implement Create of S with whatever
parameters you need.

Nevertheless it miserably fails:

1. It does not work with abstract types.

2. It exposes Create of T as a primitive operation of. That means that S
have to provide Create with *exactly* same arguments as ones of T! This is
a catastrophe. There is absolutely no reason for S to implement this
Create. It would have its own with parameters of its own. (Constructors are
NOT inherited)

3. You still cannot publicly extend T if you have to add some new
discriminants. Discriminants still are not properly abstracted.

(This cannot be saved, it is just wrong.)

>> In order to be used in
>> 
>>    type S is new T with ...;
>>    function Create (....) return S;

> (Deriving publicly
> from an abstract limited type with unknown discriminants--to me,
> the <> signals the intent of the author of T, namely that T
> should be considered none of our business?)

Exactly. This is why a user of public T must be able to construct T knowing
nothing about the discriminants of T.

>> Remember? Constructor is not function. It never will. See the problem?
> 
> Assuming C++ has constructors, will your arguments apply
> in the following examples (just trying to understand):
> 
> class T
> {
> public:
>   virtual void op() = 0;
> private:
>   T(char constraint) : c(constraint) {}
>   char c;
> };

No, the constructor in the example must be public. Probably you refer to
the trick when <> is used to prevent uninitialized objects. But T is
already abstract. You cannot create it in any way.

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



  reply	other threads:[~2009-02-28 13:45 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-19 17:37 Language lawyer question: task activation Adam Beneschan
2009-02-19 17:57 ` Dmitry A. Kazakov
2009-02-19 23:57   ` Robert A Duff
2009-02-20 13:22     ` Dmitry A. Kazakov
2009-02-23  7:36       ` Jean-Pierre Rosen
2009-02-20  5:43   ` christoph.grein
2009-02-20 10:44     ` Dmitry A. Kazakov
2009-02-20 11:14       ` christoph.grein
2009-02-20 12:07         ` mockturtle
2009-02-20 13:22           ` Dmitry A. Kazakov
2009-02-20 16:45             ` Georg Bauhaus
2009-02-20 18:41               ` Dmitry A. Kazakov
2009-02-20 22:19                 ` Georg Bauhaus
2009-02-21  8:31                   ` Dmitry A. Kazakov
2009-02-27 23:29                     ` Randy Brukardt
2009-02-28  8:13                       ` Why constructing functions is a mess [was Language lawyer question: task activation (was: Language lawyer question: task activation)) Dmitry A. Kazakov
2009-02-28 12:20                         ` Why constructing functions is a mess [was Language lawyer question: task activation Georg Bauhaus
2009-02-28 13:45                           ` Dmitry A. Kazakov [this message]
2009-02-28 15:36                             ` Georg Bauhaus
2009-02-28 16:22                               ` Dmitry A. Kazakov
2009-02-28 17:19                                 ` Georg Bauhaus
2009-02-28 17:48                                   ` Dmitry A. Kazakov
2009-02-28 18:39                                     ` Georg Bauhaus
2009-02-28 20:17                                       ` Dmitry A. Kazakov
2009-03-02 16:13                                         ` Georg Bauhaus
2009-03-02 17:46                                           ` Dmitry A. Kazakov
2009-03-02 18:50                                             ` Georg Bauhaus
2009-03-02 21:02                                               ` Dmitry A. Kazakov
2009-03-03  7:04                                                 ` christoph.grein
2009-03-03  8:45                                                   ` Dmitry A. Kazakov
2009-03-03  9:27                                                     ` christoph.grein
2009-03-03  9:34                                                       ` Dmitry A. Kazakov
2009-03-03 19:13                                                       ` Pascal Obry
2009-03-04  5:29                                                         ` christoph.grein
2009-03-04  8:32                                                           ` Dmitry A. Kazakov
2009-03-04  9:05                                                             ` christoph.grein
2009-03-04  9:47                                                               ` Dmitry A. Kazakov
2009-02-28 23:12                             ` Maciej Sobczak
2009-03-01  8:23                               ` Dmitry A. Kazakov
2009-02-19 23:54 ` Robert A Duff
2009-02-20 10:18 ` Robert_Matthews
2009-02-20 10:34   ` christoph.grein
2009-02-20 14:16   ` Robert A Duff
2009-02-20 16:57     ` Robert_Matthews
replies disabled

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