comp.lang.ada
 help / color / mirror / Atom feed
* Re: Type inference in loops with immediate constants
@ 2003-06-26  6:18 christoph.grein
  0 siblings, 0 replies; 3+ messages in thread
From: christoph.grein @ 2003-06-26  6:18 UTC (permalink / raw)
  To: comp.lang.ada

> Length : Positive; -- reminder : subtype Integer range 1 .. Integer'Last
>
> for Index in 0 .. Length - 1 loop
>
> ---
>
> Then what type Index should be ?
>
> Positive ?
>
> Obviously not, because of the 0, which is not a Positive, as a starting
> value.
>
> Integer ?
>
> Is the compiler using the fact that a positive is derived from an universal
> integer and thus decides to give the base type to the loop variable ?

Note that Positive is not a type, but a subtype of Integer. So Index is of type 
Integer with a constraint of 0 .. Length -1.



^ permalink raw reply	[flat|nested] 3+ messages in thread
* Type inference in loops with immediate constants
@ 2003-06-25 20:54 Guillaume Foliard
  2003-06-26  1:40 ` Jeffrey Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Guillaume Foliard @ 2003-06-25 20:54 UTC (permalink / raw)


Hi,

I'm currently chasing down a Constraint_Error exception and while I was
reading one loop statement I wondered about the type inference in such a
place. Here is the snippet :

---

Length : Positive; -- reminder : subtype Integer range 1 .. Integer'Last

for Index in 0 .. Length - 1 loop

---

Then what type Index should be ?

Positive ?

Obviously not, because of the 0, which is not a Positive, as a starting
value.

Integer ?

Is the compiler using the fact that a positive is derived from an universal
integer and thus decides to give the base type to the loop variable ?

-- 
Guillaume



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-06-26  6:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-26  6:18 Type inference in loops with immediate constants christoph.grein
  -- strict thread matches above, loose matches on Subject: below --
2003-06-25 20:54 Guillaume Foliard
2003-06-26  1:40 ` Jeffrey Carter

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