comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Specialization generic package parameters
Date: Sat, 24 May 2008 16:07:16 +0200
Date: 2008-05-24T16:07:17+02:00	[thread overview]
Message-ID: <13vi285cxn9q4.1p027if4to55i$.dlg@40tude.net> (raw)
In-Reply-To: ufxs7kguv.fsf@nasa.gov

On Sat, 24 May 2008 08:48:40 -0400, Stephen Leake wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> Recently I ran into the following problem with generic packages. Consider
>>
>>    type T is tagged null record;
>>
>> and a generic package that uses it:
>>
>>    generic
>>       type Some_T is new T with private;
>>    package P is
>>       ...
>>    private
>>       ...
>>    end P;
> 
>>
>> Let there be some type S derived from T:
>>
>>    type S is new T with null record;
>>
>> Now the question is, how to derive another package Q from P, specialized
>> for S, while keeping access to the private part of P?
>>
> Factor out the types and operations currently in the private part of P
> into a helper child package P.Ops.

You mean to make adaptors to the things in the private part of P in order
to access them having only public view? This is same as to make everything
in P public. Same bad design but much less clutter...

> How would you do this in some other language?

I didn't think about it. C++ does not have contracted generics anyway.

----------------
[OT]

I always had an impression that generic children were poorly designed. They
should rather extend the parent, much like types extension does. When you
derive B from A, you become one new type. When you extend a generic P with
a generic P.Q, you get two packages, each to instantiate. Generic formal
parameters are analogous to discriminants:

   type A (Par_1 : X) is tagged ...
   type B (Par_2 : Y) is new A (Par_1 => <override discriminants>) with
   record
      <extend type>
   end record;

   generic
      type Par_1 is ...
   package P is ... end P;
   generic                             -- This is not Ada!
      type Par_2 is ...
   package Q is new P (Par_1 => <override parameters>) with
      <extend body>
   end Q;

Between "Q is" and "new P" there probably should be a declarative region in
order to declare some things the overriding of parent's parameters could
refer to (without any visibility to P of course).

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



      reply	other threads:[~2008-05-24 14:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-23 17:29 Specialization generic package parameters Dmitry A. Kazakov
2008-05-23 20:17 ` christoph.grein
2008-05-24  8:00   ` Dmitry A. Kazakov
2008-05-24 12:48 ` Stephen Leake
2008-05-24 14:07   ` Dmitry A. Kazakov [this message]
replies disabled

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