comp.lang.ada
 help / color / mirror / Atom feed
From: "J-P. Rosen" <rosen@adalog.fr>
Subject: Re: How to declare a generic formal type "covered" by another?
Date: Thu, 01 May 2014 15:35:25 +0200
Date: 2014-05-01T15:35:25+02:00	[thread overview]
Message-ID: <ljtiiq$ukp$1@dont-email.me> (raw)
In-Reply-To: <slrnlm3u5u.i0l.lithiumcat@nat.rebma.instinctive.eu>

Le 01/05/2014 09:33, Natasha Kerensikova a écrit :
> The examples I had in mind are:
>   - T is Stream_Element_Array, S is Stream_Element_Array (1 .. 4096)
This is an unconstrained type and a constrained subtype of it.

>   - T is Root_Stream_Type'Class, S is a concrete type derived from it
This is an indefinite type, and a definite type derived from it.

>> 3) There is no way to say that S must be constrained, because being
>> constrained is a matter of subtype, and only types matter for generics.
> 
> Well maybe the problem here is my limited vocabulary. I used the word
> "constrained" there only to mean "Something := new S" or "Variable : S;"
> are both valid, i.e. objects of that type can be created without
> further information.
This is definite vs. indefinite types.

> There must be some way to express that in generics.
An unknown discriminant in a formal, i.e. "(<>)", expresses that the
type may be indefinite.

Now, thinking about it... When you derive a formal from an indefinite
type, it stays indefinite. OTOH, you can derive from a definite type and
give unknown discriminants to make indefinite. Add to that that a type
is considered derived from itself, and the following compiles OK:

procedure Essai is
   generic
      type T is private;
      type S (<>) is new T;
   procedure P;
   procedure P is
      X : T;
   begin
      null;
   end;
   subtype CS is String (1..10);
   procedure Inst is new P (CS, String);
begin
   null;
end Essai;

Close enough to what you wanted?
-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

  reply	other threads:[~2014-05-01 13:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-01  6:54 How to declare a generic formal type "covered" by another? Natasha Kerensikova
2014-05-01  7:09 ` J-P. Rosen
2014-05-01  7:33   ` Natasha Kerensikova
2014-05-01 13:35     ` J-P. Rosen [this message]
2014-05-01 17:56       ` Natasha Kerensikova
2014-05-01 20:59     ` Jeffrey Carter
2014-05-02  7:58       ` AdaMagica
2014-05-02  8:17         ` Natasha Kerensikova
2014-05-02 15:12         ` Jeffrey Carter
2014-05-02 15:33           ` Dmitry A. Kazakov
2014-05-02 16:00           ` AdaMagica
2014-05-01  9:30 ` Georg Bauhaus
2014-05-01  9:32 ` Georg Bauhaus
2014-05-01  9:33 ` Georg Bauhaus
2014-05-01 16:34 ` Georg Bauhaus
2014-05-01 18:11   ` Natasha Kerensikova
replies disabled

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