comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Inferring array index type from array object
Date: Wed, 23 Jun 2010 23:24:00 +0300
Date: 2010-06-23T23:24:00+03:00	[thread overview]
Message-ID: <88f8r0Fh1gU1@mid.individual.net> (raw)
In-Reply-To: <4c221952$0$2366$4d3efbfe@news.sover.net>

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
       .      @       .



  reply	other threads:[~2010-06-23 20:24 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-23  7:30 Inferring array index type from array object Maciej Sobczak
2010-06-23  8:01 ` Dmitry A. Kazakov
2010-06-23  9:03   ` J-P. Rosen
2010-06-23 12:24     ` Georg Bauhaus
2010-06-23 12:52       ` J-P. Rosen
2010-06-23 19:09         ` Simon Wright
2010-06-24  7:25           ` Georg Bauhaus
2010-06-23 14:38     ` Robert A Duff
2010-06-23 15:17       ` J-P. Rosen
2010-06-23 17:17         ` Robert A Duff
2010-06-24  6:16           ` J-P. Rosen
2010-06-23 12:13   ` Niklas Holsti
2010-06-23 14:27     ` Peter C. Chapin
2010-06-23 20:24       ` Niklas Holsti [this message]
2010-06-23 16:33     ` Warren
2010-06-23 17:49       ` Dmitry A. Kazakov
2010-06-23 18:45         ` Warren
2010-06-23 20:39       ` Niklas Holsti
2010-06-28 13:44         ` Warren
2010-06-28 22:18           ` Niklas Holsti
2010-06-29  1:49             ` Adam Beneschan
2010-06-29  2:10               ` (see below)
2010-06-29 16:56             ` Warren
2010-06-29 17:50               ` John B. Matthews
2010-06-29 19:31                 ` Warren
2010-06-29 20:06                   ` Jeffrey R. Carter
2010-06-29 20:16                     ` Warren
2010-06-29 20:22                   ` Adam Beneschan
2010-06-29 20:39                     ` Dmitry A. Kazakov
2010-06-29 20:55                     ` Warren
2010-06-29 21:00                       ` Warren
2010-06-29 21:47                         ` John B. Matthews
2010-06-29 21:52                         ` Damien Carbonne
2010-06-29 22:22                         ` Adam Beneschan
2010-06-30 16:43                           ` Warren
2010-06-29 21:18                       ` Jeffrey R. Carter
2010-06-30  5:01                     ` Simon Wright
2010-06-30 14:29                       ` Adam Beneschan
2010-06-29 20:28                   ` Damien Carbonne
2010-06-29 21:20                   ` John B. Matthews
2010-06-23 13:12 ` Gautier write-only
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox