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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-24 01:21:17 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!pd2nf1so.cg.shawcable.net!residential.shaw.ca!in.100proofnews.com!tdsnet-transit!newspeer.tds.net!gail.ripco.com!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? Date: Wed, 24 Sep 2003 10:17:59 +0200 Message-ID: References: <568ede3c.0309160929.1d0d3d95@posting.google.com> <3F67AFB9.7040001@attbi.com> <3F6F0841.60607@attbi.com> <1064244399.683441@master.nyc.kbcfp.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1064390973 5275188 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:42843 Date: 2003-09-24T10:17:59+02:00 List-Id: On Wed, 24 Sep 2003 02:13:15 GMT, Matthew Heaney wrote: >Dmitry A. Kazakov writes: > >> (**) BTW a great unsolvable problem in both Ada and C++, both with MI >> or without, is to make a container of a subtype a subtype of the >> container of the base type. Which highlights present problems with ADT >> and *helpless* attempts to solve this using templates. > >Au contraire. The *simplest* way to solve that problem is using >templates. > >package P is > type T is tagged null record; > procedure Op (O : in out T); >end P; > >package P.C is > type NT is new T with null record; > procedure Op (O : in out T); >end; > > >function "<" (L, R : P.T) return Boolean is ...; > >package T_Sets is > new Ada.Containers.Sets.Sorted.Unbounded (P.T); > >function "<" (L, R : P.C.NT) return Boolean is ...; > >package NT_Sets is > new Ada.Containers.Sets.Sorted.Unbounded (P.C.NT); > > T_Set : T_Sets.Container_Type; > NT_Set : NT_Sets.Container_Type; T_Set and NT_Set are unrelated types. So one cannot be a subtype/subclass of another. It means that I cannot write a NON-GENERIC program operating on both. >Now let's say you want an algorithm that can operate over the items in >either of the set containers declared above. After all, that why you >wanted NT_Set to be a subtype of T_Set. So let's just abstract-away the >container: > > generic > type Iterator_Type is private; > with procedure Succ (Iter : Iterator_Type) > return Iterator_Type is <>; > function To_T (Iter : Iterator_Type) > return T_Class_Access; > procedure Generic_Algorithm > (First, Back : Iterator_Type); > >Now I can do this: > > function To_T is > new T_Sets.Generic_Element (T_Class_Access); --check this > > function To_T is > new NT_Sets.Generic_Element (T_Class_Access); --ditto > >And now I do this: > > procedure Algorithm is > new Generic_Algorithm (T_Sets.Iterator_Type); > > procedure Algorithm is > new Generic_Algorithm (NT_Sets.Iterator_Type); > >And so now I can do this: > > Algorithm (First (T_Set), Back (T_Set)); > Algorithm (First (NT_Set), Back (NT_Set)); > >Problem solved. No MI or base types or inheritance or interfaces or any >other crap is needed. Generics work just fine thank you very much. No, the problem is not solved. You just pushed it to another place. As a designer of the container types, you said that it is not your business, but one of a user. Who have to keep in mind that they are different types and implement all subprograms working with them generic. After all, your method is applicable not only to containers, but also to any pair of base-descendant tagged types. Why do we have them? We could keep them unrelated and re-write everything in generics. Formally it should be possible, just because both generics and class-wides represent generic programming and thus in much overlap. But techincally it is absurd. You should have expected me answering something like this. (:-)) Because my "swan-song" is to do generic programming *exclusively* with class-wides kicking generics out! --- Regards, Dmitry Kazakov www.dmitry-kazakov.de