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,5f5a48f21d7f7525 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Inferring array index type from array object Date: Wed, 23 Jun 2010 23:24:00 +0300 Organization: Tidorum Ltd Message-ID: <88f8r0Fh1gU1@mid.individual.net> References: <6b20ed09-efc1-4df7-90f9-5e141482e8d0@d37g2000yqm.googlegroups.com> <1305oqccr1h2t$.x33x4oxwd84d$.dlg@40tude.net> <88ec2vF3uqU1@mid.individual.net> <4c221952$0$2366$4d3efbfe@news.sover.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net +ReRZg/xvuwqVyj7uUouSQZx/wvcjjkW8pIVABgw1plTDHe0tC Cancel-Lock: sha1:PT4je0d038jsN/ai+mYmf/Xx4o4= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: <4c221952$0$2366$4d3efbfe@news.sover.net> Xref: g2news2.google.com comp.lang.ada:12873 Date: 2010-06-23T23:24:00+03:00 List-Id: Peter C. Chapin wrote: > Niklas Holsti wrote: > >> I don't think such large language changes would be necessary. The >> expression S'Range gives the compiler all the information about the type >> and its constraints, so I see no reason why Ada could not be extended >> simply to allow S'Range in a variable declaration, as in the above >> quoted "I : S'Range". The declared variable "I" would have the same >> (sub)type as the loop counter in "for I in S'Range loop ...". > > This seems weird to me. S'Range is a range, not a type. I agree that it > includes type information, but then so does an object. > > X : Integer; > Y : X; -- Let Y have the same type as X. Weird. Another, perhaps more readable way would be to introduce some attributes that return types: I : S'Index_Type; Y : X'Type; > Type inference is a big subject and while it can be very nice in languages > that support it comprehensively, type inference doesn't really seem like > the "Ada way" to me. I would not call these examples "type inference", as they require no global or even subprogram-wide analysis. The desired type can be derived directly from what is written locally (and, of course, from the meaning of the identifiers). > In any case, once you start supporting type inference in > any form you have to wonder just how far down that road you want to go. Right > now Ada only infers types in one very limited case (right?)... that is in > support of implicitly declared loop index variables. The type of implicitly declared loop index variables (for I in S'Range loop) needs only local analysis, so I would not call it type inference. Resolution of overloaded subprogram and operator names is much more complex and could deserve to be called type inference. But even that requires only local analysis, although (I believe) it needs more than one traversal of the syntactic structure of the (nested) call. "Real" type inference would be needed if these suggestions were extended to let variables be declared using the return type of an overloaded function call, with the overload resolution extended to take constraints from the use-sites of the variable. I won't try to give an example of that, as I agree with Peter that such non-local type inference would be against the Ada way. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .