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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,70414f56d810c10c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.25.163 with SMTP id d3mr1782829pbg.7.1316455001520; Mon, 19 Sep 2011 10:56:41 -0700 (PDT) Path: lh7ni594pbb.0!nntp.google.com!news1.google.com!postnews.google.com!n40g2000yqb.googlegroups.com!not-for-mail From: ytomino Newsgroups: comp.lang.ada Subject: Re: discriminant questions Date: Mon, 19 Sep 2011 10:49:18 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> <708a1202-d480-451b-9b55-00b31ad9c452@w28g2000yqw.googlegroups.com> <1kx7ltnsal62q.195k449mr947t.dlg@40tude.net> NNTP-Posting-Host: 122.29.183.131 Mime-Version: 1.0 X-Trace: posting.google.com 1316455001 18683 127.0.0.1 (19 Sep 2011 17:56:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 19 Sep 2011 17:56:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n40g2000yqb.googlegroups.com; posting-host=122.29.183.131; posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HNKUARELSC X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1,gzip(gfe) Xref: news1.google.com comp.lang.ada:18032 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-09-19T10:49:18-07:00 List-Id: > The relevant part is probably 12.5.1(14): > "The subtype of each discriminant of the actual type shall statically match > the subtype of the corresponding discriminant of the formal type." > which I read as *no formal generic discriminants*. I.e. if "statically > match" means what I think, then "element" in > type ref (element : not null access e) is private; > cannot be matched because "e" is a formal generic parameter. Thanks. Yes, I did grep RM just now and found the definition of "statically match". It's written in 4.9.1: * both are null constraints; * both are static and have equal corresponding bounds or discriminant values; * both are nonstatic and result from the same elaboration of a constraint of a subtype_indication or the same evaluation of a range of a discrete_subtype_definition; or * both are nonstatic and come from the same formal_type_declaration. <- *A* 4th clause (*A*) is probably applied. It seems that a formal type is match only itself. However, it does not explain why does int_ref (having access Integer) match the_package_use_ref.ref (having access e), since Integer is not e statically. (sorry, > I can not understand the reason that inst1 is error and inst2 is ok. This is my typo. "inst2 is error and inst3 is ok" is right.) Should inst3 be error if inst2 is error? As another reason, if it is disallowed, we can not replace generic algorithm from Ada 2005 interface to Ada 2012 interface. for example, from -- "count" algorithm with Ada 2005 version generic type Element_Type (<>) is private; type Cursor is private; type Container is private; with procedure Iterate (C : Container; Proc : access procedure (P : Cursor)); with function Element (P : Cursor) return Element_Type; procedure Generic_Count (C : Container; Value : Element_Type) return Count_Type; to -- "count" algorithm with Ada 2005 version generic type Element_Type (<>) is private; type Cursor is private; type Container is private; package Iterator_Interfaces is new Ada.Iterator_Interfaces (Cursor, others => <>); with function Iterate (C : Container) return Iterator_Interfaces.Forward_Iterator'Class; type Constant_Reference_Type ( Element : not null access constant Element_Type) with private; <- *B* with function Constant_Reference (C : Container; P : Cursor) return Constant_Reference_Type; procedure Generic_Count (C : Container; Value : Element_Type) return Count_Type; There is no way to use a instance of Vectors.Constant_Reference_Type as *B*. We have to use Element or Query_Element still in generic. I feel this is strange and I think designer(s) of new containers did not intend it. > As a work-around, make the second package a child or pass the first one as > a parameter to it. It means that we have to write plural versions of Generic_Count for Vectors, for Doubly_Linked_Lists, for Ordered_Sets and more.