comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Question regarding example code in AI12-0140
Date: Thu, 30 Oct 2014 09:21:03 -0700 (PDT)
Date: 2014-10-30T09:21:03-07:00	[thread overview]
Message-ID: <faf21058-7255-4b11-b57b-55b5641d5ccd@googlegroups.com> (raw)
In-Reply-To: <f7645ba6-7b61-4337-adec-77954318e0d6@googlegroups.com>

On Thursday, October 30, 2014 8:59:31 AM UTC-7, Mark Lorenzen wrote:
> Hello
> 
> In AI-0140 the following example code is given:
> 
> with Ada.Unchecked_Deallocation;
> 
> package UNC is
> 
>    type My_String (<>) is limited private;
>    type My_String_Access is access My_String;
> private
>    type My_String is new String;
>    procedure Free is new
>      Ada.Unchecked_Deallocation (My_String, My_String_Access);
> 
> end UNC;
> 
> The AI discusses if this is legal Ada or not.
> 
> I have never used nor seen a formal generic type used in this way, where the full view of the type seems to strengthen the partial view. Can anyone enlighten me to what the intention of the author could be?

There are no formal generic types in this example, because you're not defining a generic.  Perhaps you're confused because (<>) has been used since Ada 83 in formal generic types to mean "formal generic discrete type"?  But the (<>) syntax was given a new job in Ada 95.

What it means is that as far as other packages are concerned, the type may be an indefinite type.  Therefore, other packages are not allowed to define *variables* like

    X : UNC.My_String;

(for approximately the same reasons they can't define variables like this:)

    X : String;

The full view doesn't really "strengthen" the partial view here.  Since String is an indefinite type, My_String will also be an indefinite type, and the body of UNC, if there were one, would also not be able to say

    Y : My_String;

It would be legal to make the full view a definite type, however, such as

    type My_String is new String(1..100);

The contract between UNC and its clients would still be that, as far as the clients are concerned, My_String is an indefinite type, and UNC would be reserving the right to change the implementation to an indefinite type in the future.

                              -- Adam

  reply	other threads:[~2014-10-30 16:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 15:59 Question regarding example code in AI12-0140 Mark Lorenzen
2014-10-30 16:21 ` Adam Beneschan [this message]
2014-10-31 10:11   ` Mark Lorenzen
2014-10-31 19:40 ` AdaMagica
2014-11-01 15:31   ` Brad Moore
2014-11-08  3:58   ` Randy Brukardt
2014-11-08 19:20     ` AdaMagica
replies disabled

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