comp.lang.ada
 help / color / mirror / Atom feed
* Question regarding example code in AI12-0140
@ 2014-10-30 15:59 Mark Lorenzen
  2014-10-30 16:21 ` Adam Beneschan
  2014-10-31 19:40 ` AdaMagica
  0 siblings, 2 replies; 7+ messages in thread
From: Mark Lorenzen @ 2014-10-30 15:59 UTC (permalink / raw)


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?

Regards,

Mark L


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

* Re: Question regarding example code in AI12-0140
  2014-10-30 15:59 Question regarding example code in AI12-0140 Mark Lorenzen
@ 2014-10-30 16:21 ` Adam Beneschan
  2014-10-31 10:11   ` Mark Lorenzen
  2014-10-31 19:40 ` AdaMagica
  1 sibling, 1 reply; 7+ messages in thread
From: Adam Beneschan @ 2014-10-30 16:21 UTC (permalink / raw)


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

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

* Re: Question regarding example code in AI12-0140
  2014-10-30 16:21 ` Adam Beneschan
@ 2014-10-31 10:11   ` Mark Lorenzen
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Lorenzen @ 2014-10-31 10:11 UTC (permalink / raw)


On Thursday, October 30, 2014 5:21:04 PM UTC+1, Adam Beneschan wrote:

> 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.

Of course - my bad! Thanks for the clarification.

Regards,

Mark L

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

* Re: Question regarding example code in AI12-0140
  2014-10-30 15:59 Question regarding example code in AI12-0140 Mark Lorenzen
  2014-10-30 16:21 ` Adam Beneschan
@ 2014-10-31 19:40 ` AdaMagica
  2014-11-01 15:31   ` Brad Moore
  2014-11-08  3:58   ` Randy Brukardt
  1 sibling, 2 replies; 7+ messages in thread
From: AdaMagica @ 2014-10-31 19:40 UTC (permalink / raw)


Am Donnerstag, 30. Oktober 2014 16:59:31 UTC+1 schrieb Mark Lorenzen:
> 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.

Hu - I've got severe problems to understand the AI. It says:
"The full view of My_String is constrained, while My_String_Access designates the partial view of My_String, which is unconstrained."

But since when is type String constrained? So why is the full view of My_String constrained?

Am I blind?

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

* Re: Question regarding example code in AI12-0140
  2014-10-31 19:40 ` AdaMagica
@ 2014-11-01 15:31   ` Brad Moore
  2014-11-08  3:58   ` Randy Brukardt
  1 sibling, 0 replies; 7+ messages in thread
From: Brad Moore @ 2014-11-01 15:31 UTC (permalink / raw)


On 14-10-31 01:40 PM, AdaMagica wrote:
> Am Donnerstag, 30. Oktober 2014 16:59:31 UTC+1 schrieb Mark Lorenzen:
>> 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.
>
> Hu - I've got severe problems to understand the AI. It says:
> "The full view of My_String is constrained, while My_String_Access designates the partial view of My_String, which is unconstrained."
>
> But since when is type String constrained? So why is the full view of My_String constrained?
>
> Am I blind?
>

The AI needs some cleanup, and the sentence in the question that says;

"The full view of My_String is constrained, while My_String_Access 
designates the partial view of My_String, which is unconstrained. "

is misleading and incorrect, since as you you point out type My_String 
is an unconstrained subtype as defined in RM 3.2(9).

The original issue was not really about the My_String type. It was about 
the My_String_Access type. It's declaration in the public part of the 
package is that of an access type that designates a type that has 
unknown discriminants. Any subtype of a type with unknown discriminants 
is an unconstrained and indefinite subtype. see RM 3.7 (26)

However in the private part of the package where the instantiation 
occurs and the full view of My_String can be seen, we find out that 
My_String has no discriminants, which is not the same as having unknown 
discriminants.

In the instantiation of Unchecked_Deallocation, the My_String generic 
formal has no discriminants. The other generic formal, Name has has to 
designate a type that statically matches the Object formal, yet at first 
glance these do not appear to match.

RM 4.9.1 (1.2/2) A constraint statically matches another constraint if:
both are static and have equal corresponding bounds or discriminant values;

In the Appendix of the AI however, Tucker explains that for statically 
matching, it is the properties of the designated type that matter, not 
the properties of the access type that designates them. "The properties 
of the designated type change as you learn more about the designated 
type." He further points out that the access types in question are 
exactly the *same* type, so they should match each other statically. 
That is, both the access type declared in the public part of the package 
and the view of the access type in the private part designate the 
My_String type.

So the effect of this AI would likely just be a clarification in the 
wording of the RM, but most compilers otherwise would not need any 
changes. In Randy's case he would need to make a change to his compiler, 
because he has a compiler bug.

Brad


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

* Re: Question regarding example code in AI12-0140
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2014-11-08  3:58 UTC (permalink / raw)


"AdaMagica" <christ-usch.grein@t-online.de> wrote in message 
news:bc4efa4f-7b39-4ca8-8c3b-503eef0039ea@googlegroups.com...
> Am Donnerstag, 30. Oktober 2014 16:59:31 UTC+1 schrieb Mark Lorenzen:
>> 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.
>
> Hu - I've got severe problems to understand the AI. It says:
> "The full view of My_String is constrained, while My_String_Access 
> designates the partial view of My_String, which is unconstrained."
>
> But since when is type String constrained? So why is the full view of 
> My_String constrained?
>
> Am I blind?

I ran out of time to re-check the logic of this one before making it into an 
AI. So I copied the original discussion directly into the AI, but I agree it 
makes no sense as written. I'm sure I meant that the *partial view* is 
constrained. Brad points out that 3.7(26) says that it is unconstrained and 
indefinite, but this is not intended to be normative wording and only the 
"indefinite" part is backed up by other wording in the Standard (at least 
that I can find in a 30 second search of the RM).

In any case, the truly operative part is that we're statically matching a 
type with unknown discriminants to a type with no discriminants (and 
unconstrained bounds), and nothing in the Standard says that's allowed. 
("Nothing" certainly being different than "unknown"). I agree that the 
wording *should* allow this (the language would not make much sense if two 
views of the same subtype didn't match), but it doesn't. Thus the AI. (Why 
Janus/Ada implements this litererally, I don't know, but it's probably 
related to trying to get some ACATS test with picky rules checks to pass.)

                                       Randy.




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

* Re: Question regarding example code in AI12-0140
  2014-11-08  3:58   ` Randy Brukardt
@ 2014-11-08 19:20     ` AdaMagica
  0 siblings, 0 replies; 7+ messages in thread
From: AdaMagica @ 2014-11-08 19:20 UTC (permalink / raw)


On Saturday, November 8, 2014 4:58:35 AM UTC+1, Randy Brukardt wrote:

Thank you, Randy, for your explanation. I (perhaps naively) assumed that a type with unknown discriminants, since unconstrained, is just this - an unconstrained type. So where's the problem?

Now I see why some wording is needed: "nothing" definitely *is* different from "unknown".

Christoph


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

end of thread, other threads:[~2014-11-08 19:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-30 15:59 Question regarding example code in AI12-0140 Mark Lorenzen
2014-10-30 16:21 ` Adam Beneschan
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

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