comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: derived formal types and known discriminants
Date: Mon, 3 Jul 2017 10:24:25 -0700 (PDT)
Date: 2017-07-03T10:24:25-07:00	[thread overview]
Message-ID: <bcfa29e1-f02c-4fd6-9d2c-d86883589166@googlegroups.com> (raw)
In-Reply-To: <a9316065-923c-439e-9176-8f3eb469c601@googlegroups.com>

On Thursday, June 22, 2017 at 8:45:22 PM UTC-4, sbelm...@gmail.com wrote:
> Can any language lawyer explain the reasoning behind precluding known discriminants for general formal derived types?  For example, I can write this:
> 
> generic
>   type T is new P with private; -- constrained (i.e. none)
>   
> and I can write this:
> 
> generic
>   type T (<>) is new P with private;  -- unconstrained (i.e. any)
>   
> But I can't write
> 
> generic
>   type T (foo : Integer) is new P with private;  -- (just one integer)
>   
> presumably because 12.5.1~11/3 says "The declaration of a formal derived type shall not have a known_discriminant_part", to wit GNAT complains "discriminants not allowed for this formal type".  It would seems as though if unknown discriminants are legal, known would be an easier subset, and my interest has been piqued to the reason why.
> 
> Thank you for any insight
> 
> -sb

I've often wondered this myself.  The best I came up with was to use an intermediate type:

type NP(Foo : Integer) is new P with null record;

and then do the generic like this:

generic
   type T is new NP with private;
package G is
   subtype Test_Type is T;
end G;

A bit more cumbersome, but that's how I managed it.


      parent reply	other threads:[~2017-07-03 17:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23  0:45 derived formal types and known discriminants sbelmont700
2017-06-23 17:26 ` Randy Brukardt
2017-06-29 14:15   ` sbelmont700
2017-06-29 14:39     ` Dmitry A. Kazakov
2017-06-29 17:40       ` Robert Eachus
2017-06-30  1:10     ` Randy Brukardt
2017-06-30  7:24       ` Dmitry A. Kazakov
2017-06-30 18:09         ` Randy Brukardt
2017-07-04  0:30           ` sbelmont700
2017-07-04  1:36             ` gautier_niouzes
2017-07-04  2:29             ` Randy Brukardt
2017-07-04  7:09             ` Dmitry A. Kazakov
2017-07-04 17:34               ` Shark8
2017-07-03 17:24 ` Jere [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