comp.lang.ada
 help / color / mirror / Atom feed
* What is an indefinite type and is there an example of it?
@ 2016-09-08  1:20 Andrew Shvets
  2016-09-08  2:39 ` Jeffrey R. Carter
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Shvets @ 2016-09-08  1:20 UTC (permalink / raw)


Hello,

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?

Also, I'm trying -- and not succeeding -- to make a minimum example of how to do this in Ada.  This is what I have so far and the compiler complains that there is no range defined.  My example could use some serious work.

with Ada.Text_IO;

procedure Indefinite_Type is
  type Unknown (<>) is ...;
  Integer : Unknown := 0;
begin
  null;
end Indefinite_Type;


Thank you in advance.

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

* Re: What is an indefinite type and is there an example of it?
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey R. Carter @ 2016-09-08  2:39 UTC (permalink / raw)


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


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

end of thread, other threads:[~2016-09-08  2:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox