From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,33afa3244ab891f7 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Specialization generic package parameters Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1996bbhvwjxcr$.1s16brw83713g$.dlg@40tude.net> Date: Sat, 24 May 2008 16:07:16 +0200 Message-ID: <13vi285cxn9q4.1p027if4to55i$.dlg@40tude.net> NNTP-Posting-Date: 24 May 2008 16:07:17 CEST NNTP-Posting-Host: 786602c5.newsspool1.arcor-online.net X-Trace: DXC=Qhk;Ieb6c[@lU`@c^jLCbJic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgB3Geomji7S On Sat, 24 May 2008 08:48:40 -0400, Stephen Leake wrote: > "Dmitry A. Kazakov" 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 => ) with record 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 => ) with 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