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-Thread: 103376,bf5045b7cee3d4b X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news.cs.univ-paris8.fr!u-psud.fr!not-for-mail From: Philippe Tarroux Newsgroups: comp.lang.ada Subject: Re: tagged type as generic parameter Date: Fri, 04 Jan 2008 14:08:52 +0100 Organization: University Paris-Sud, France. Message-ID: References: NNTP-Posting-Host: osiris.limsi.fr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news2.u-psud.fr 1199452037 10464 129.175.157.197 (4 Jan 2008 13:07:17 GMT) X-Complaints-To: newsmaster@u-psud.fr NNTP-Posting-Date: Fri, 4 Jan 2008 13:07:17 +0000 (UTC) User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) In-Reply-To: Xref: g2news1.google.com comp.lang.ada:19191 Date: 2008-01-04T14:08:52+01:00 List-Id: Dmitry A. Kazakov a �crit : > > The function A_Data returns Data. It is a primitive operation of Data and > thus covariant in the result. So when you derive anything from Data, you > have to override it in order to provide a correct implementation that would > return the derived type rather than the base. > Ok. But does it mean that only the constructor is a primitive operation of the data type, not the print procedure? In this case why Print doesn't need to be redefined? > There are many ways to resolve the issue, the choice depends on other > factors: > > 1. Class-wide A_Data: > > function A_Data (V : Integer) return Data'Class; > > This will be same (contravariant) for all descendants of A_Data and thus > need not to overridden. > > 2. Data-specific List package: > > generic > type Data is abstract new Data_Handler.Data with private; > package Data_List is > ... > type Item is new Data with record > Next : Item_Ptr; > end record; > function A_Data (V : Integer) return Item; > > We know here that Data is a descendant of Data_Handler.Data, so we can > provide an override for A_Data. > > 3. Aggregation instead of inheritance: > > type Item is record > Next : Item_Ptr; > Value : Data; > end record; > > No inheritance, no problem. > > 4. Non-generic implementation of lists. You can define a list interface and > derive Data_Handler.Data from a list item. (In Ada 2005 it is easier to do > than it was in Ada 95) That would reverse the inheritance order and thus > solve the problem with A_Data. > > 5. Storage-pool based implementation of lists. You can design a storage > pool that would maintain lists of allocated there items. In this case, > unlikely to all other variants, the list item is not a fully separate type > but just a pool-specific access to Data type. Because there again is no > inheritance involved, the problem is solved. > Thanks for all these suggestions that bring to me interesting insights. Especially i know that #4 solves the problem (it is the alternative proposed in Barnes for the construction of list items). I won't be aware of #5. I will try it. Regards Philippe Tarroux