From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: How to declare a generic formal type "covered" by another? Date: Thu, 01 May 2014 15:35:25 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 1 May 2014 13:35:22 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="214e2226c9a2cb4f71713357be0d6925"; logging-data="31385"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KEPup97E6ViWTXYKlXIoz" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: Cancel-Lock: sha1:zzYFetB6nw1pklUXyLvcv/VpQBw= X-Enigmail-Version: 1.6 Xref: news.eternal-september.org comp.lang.ada:19635 Date: 2014-05-01T15:35:25+02:00 List-Id: 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