comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: What is an indefinite type and is there an example of it?
Date: Wed, 7 Sep 2016 19:39:45 -0700
Date: 2016-09-07T19:39:45-07:00	[thread overview]
Message-ID: <nqqj1m$shq$1@dont-email.me> (raw)
In-Reply-To: <09169c05-5c31-40a6-8523-89aab3bca72e@googlegroups.com>

On 09/07/2016 06:20 PM, Andrew Shvets wrote:
> 
> I'm trying to figure out what an indefinite type is.  Ada Distilled doesn't
> even have the string "indefinite" in the entire document.  The Ada wikibook
> seems to say that it's a type of that does not have its range defined... ok,
> so does that make it an array that doesn't have it range defined at
> compile-time?  Is there more to this that I'm missing?

"Indefinite subtype" is defined in ARM 3.3 (23/3): "A subtype is an indefinite
subtype if it is an unconstrained array subtype, or if it has unknown
discriminants or unconstrained discriminants without defaults (see 3.7);
otherwise, the subtype is a definite subtype (all elementary subtypes are
definite subtypes)."

http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-3-3.html#I1468

(Although the ARM isn't very good for learning the language, once you have a
grasp of the language, it can be helpful for investigating specific topics like
this.)

In simple terms, a subtype is definite if you can declare a variable of the
subtype without giving any additional information, and indefinite if you can't.
So, since you can't say

S : String;

String is indefinite; you have to give additional information (the bounds for S)
either explicitly

S : String (1 .. 6);

or through initialization

S : String := Ada.Text_IO.Get_Line;

Similarly, given a record type with discriminants without defaults

type Rec (Max : Positive) is record
   Len : Natural := 0;
   Val : String (1 .. Max) := (1 .. Max => ' ');
end record;

you can't say

R : Rec;

so Rec is indefinite. You have to provide a value for Max somehow.

The unknown discriminant notation (<>) is used with a private type in a pkg to
force clients to provide initialization for objects of the type

package P is
   type T (<>) is private;

   function F return T;
private -- P
   ...
end P;

It's also used for generic formal types to indicate that an instantiation of the
generic won't do anything with the type that can't be done with an indefinite
type, so it may be instantiated with an indefinite actual type.

generic -- G
   type T (<>) is private;
package G is
   ...
end G;

-- 
Jeff Carter
"I used to manufacture escalator shoes for people
who were nauseous in elevator shoes."
Take the Money and Run
142


      reply	other threads:[~2016-09-08  2:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08  1:20 What is an indefinite type and is there an example of it? Andrew Shvets
2016-09-08  2:39 ` Jeffrey R. Carter [this message]
replies disabled

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