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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Ada Distilled problem Date: Fri, 4 Mar 2016 12:01:34 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 4 Mar 2016 18:58:32 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="48b46be33beed75863f69afa437f956b"; logging-data="331"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18umuZ2OFtMqp3zrG0+N5EcXZ2whJ5+phc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: X-Mozilla-News-Host: news://freenews.netfront.net Cancel-Lock: sha1:naaTpPMMmKk5Xlsy3pUmv+UELPg= Xref: news.eternal-september.org comp.lang.ada:29672 Date: 2016-03-04T12:01:34-07:00 List-Id: On 03/04/2016 11:21 AM, Simon Wright wrote: > A Stack Overflow user has been having problems[1] trying to use the > queue manager described at page 82 of Ada Distilled (2005 version)[2]. > > To see the problem in its essentials, the (inoperative!) spec could be > > generic > type Element is tagged private; > package Lists is > type Item is new Element with private; > type List is tagged private; > > procedure Insert (Self : in out List; I : Item'Class); > > private > type Item is new Element with null record; > type List is tagged null record; > end Lists; > > with a calling program > > with Lists; > procedure Main is > type Temp is tagged null record; > package Temp_List is new Lists (Temp); > > FL : Temp_List.List; > > Instance : Temp := Temp'(null record); > > begin > Temp_List.Insert (Self => FL, I => Instance); > end Main; > > resulting in > > main.adb:11:40: expected type "Item'Class" defined at lists.ads:4, > instance at line 4 > main.adb:11:40: found type "Temp" defined at line 3 > > and I can't see any way of twisting this so it can compile. And, in any > case, what is the point of "type Item"? I agree. This seems to be a case of extension for the sake of extension. Insert should take an Element, or Element'Class if you think that buys the client something. In either of those cases, the example should compile as is. You could get the example to compile by changing Instance to Instance : Temp_List.Item; but I don't know how to explicitly initialize Instance, and using such a value in real life is complicated by it being a private extension. The extension seems to be "backward". One could write the pkg > package Lists is > type Element is tagged private; > type List is tagged private; > > procedure Insert (Self : in out List; Item : in Element'Class); > private > type Item is tagged null record; > type List is tagged null record; > end Lists; and then declare Temp as type Temp is new Lists.Element with ... which works with some type conversions, but in general requiring clients to use a container that contain indefinite types, even when only a single type is going to be stored, seems like a poor design, and having the root of the class be a private extension of a client-provided type, a mistake. -- Jeff Carter "The men get one hot meal a day: a bowl of steam." Take the Money and Run 145