comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Generic package parameters not externally visible : what's the rational ?
Date: Thu, 29 Oct 2009 09:36:39 +0100
Date: 2009-10-29T09:36:39+01:00	[thread overview]
Message-ID: <1kf8mo4r9lqxg.1tdhqe6femt9m.dlg@40tude.net> (raw)
In-Reply-To: hca5gv$kvg$1@munin.nbi.dk

On Wed, 28 Oct 2009 14:19:58 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:10eygvuzeit9g.xwy2wanxoxgf$.dlg@40tude.net...
>> On Tue, 27 Oct 2009 16:08:09 -0500, Randy Brukardt wrote:
> ...
>>> I'm not sure that it "makes perfect sense" for them to be visible: it would
>>> surely increase the chance of name collisions outside of the package.
>>
>> Sorry, but that is a "generic" property of anything declared in a generic
>> package. Two instances of the same generic packages always collide when
>> "use"-ed.
> 
> No, I was thinking of name collisions when the formal and actual have the 
> same name (that is very common for subprogram parameters and is not uncommon 
> in generic as well). If the formal is also visible, you end up with two 
> things with the same name. Something like:
> 
>    generic
>        type Int is range <>;
>    package Gen is
>        ...
>    end Gen;
> 
>    with Gen;
>    package Test is
>        type Int is range ...;
>        package My_Gen is new Gen (Int);
>    end Test;
> 
>    with Test;
>    procedure Check is
>       use Test, Test.Gen;
>       Obj : Int; -- (1)
>    ...
> 
> (1) is legal by the current rules, but if the formal was visible, it would 
> become illegal because there would be two Int's visible. That would become 
> worse if any of the proposals for integrated instantiations are adopted, 
> because both Ints would be visible in the same scope, and thus use Test 
> would become ineffective: exactly the reverse of what is wanted from an 
> integrated instantiation.

It is clear that some code will become illegal. Here is another example of
a collision upon instantiation in the current version of Ada:

   generic
      type I is (<>);
   package P is
      type T is tagged null record;
      procedure Foo (Obj : T; X : I);
      procedure Foo (Obj : T; X : Integer);
   end P;

   package Bar is new P (Integer); -- Boom!

I don't think we should much care about backward compatibility with regard
to generics.

My take is that any generic code is potentially broken. Anyone who uses
generics beyond very trivial cases should know that, and mentally prepare
himself to fix his code over and over again.

>>> That's clear from the
>>> syntax (they're outside the package). You're going to say that discriminants
>>> are outside of the type, too, but they're also visible. I can't argue with
>>> that beyond saying that that placement of discriminants is just awful; I
>>> place them in the wrong place and continually forget to include them in
>>> aggregates because they're well away from the other components.
>>
>> That depends on the mental model of the discriminant. If the discriminant
>> is a type constraint, then you are right. But in Ada this concept, if ever
>> existed, has been eroded. Presently discriminant is merely an immutable
>> component. I am also in favor the "constraint" model, and yes, in this
>> model it would be reasonable to make discriminants invisible, e.g. when
>> they are used for construction and then dropped. But that is not the Ada
>> model now.
> 
> ...other than for Unchecked_Unions, and even there the model is incomplete. 
> (You can reference the discriminant in a context where it can be determined, 
> such as for a constrained object, even though it is not stored anywhere. But 
> you can't reference it if the object is unconstrained.)

Yes, I also thought about Unchecked_Unions. It would be great to have
checked Unchecked_Unions without "case" (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2009-10-29  8:36 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26  8:58 Generic package parameters not externally visible : what's the rational ? Hibou57 (Yannick Duchêne)
2009-10-26 11:05 ` Ludovic Brenta
2009-10-26 15:02   ` Robert A Duff
2009-10-27  1:06   ` Hibou57 (Yannick Duchêne)
2009-10-26 14:56 ` Robert A Duff
2009-10-27  3:03   ` Hibou57 (Yannick Duchêne)
2009-10-27 21:08   ` Randy Brukardt
2009-10-27 21:36     ` Jeffrey R. Carter
2009-10-27 22:03       ` Hibou57 (Yannick Duchêne)
2009-10-27 22:19         ` Jeffrey R. Carter
2009-10-28 19:07         ` Randy Brukardt
2009-10-29 12:18           ` Hibou57 (Yannick Duchêne)
2009-10-29 22:56             ` Randy Brukardt
2009-10-30  0:10               ` Hibou57 (Yannick Duchêne)
2009-10-27 22:04       ` Hibou57 (Yannick Duchêne)
2009-10-27 23:37       ` Robert A Duff
2009-10-27 23:41         ` Jeffrey R. Carter
2009-10-27 23:34     ` Robert A Duff
2009-10-28  2:19       ` Hibou57 (Yannick Duchêne)
2009-10-28 19:12         ` Randy Brukardt
2009-10-29  7:34           ` Stephen Leake
2009-10-29 12:21           ` Hibou57 (Yannick Duchêne)
2009-10-29 13:10             ` AdaMagica
2009-10-29 15:11               ` Georg Bauhaus
2009-10-29 19:28                 ` Jeffrey R. Carter
2009-10-29 20:27                   ` Georg Bauhaus
2009-10-30 10:30               ` Stephen Leake
2009-10-30 17:53             ` Ludovic Brenta
2009-10-31  2:10               ` Hibou57 (Yannick Duchêne)
2009-10-30  5:19           ` Hibou57 (Yannick Duchêne)
2009-10-28  9:09     ` Dmitry A. Kazakov
2009-10-28 19:19       ` Randy Brukardt
2009-10-29  8:36         ` Dmitry A. Kazakov [this message]
2009-10-29 23:03           ` Randy Brukardt
2009-10-30  8:51             ` Dmitry A. Kazakov
2009-10-30 10:25           ` Stephen Leake
2009-10-30 19:32             ` Dmitry A. Kazakov
2009-10-31  2:06               ` Hibou57 (Yannick Duchêne)
2009-10-31  9:14                 ` Dmitry A. Kazakov
2009-11-03  8:25                   ` Hibou57 (Yannick Duchêne)
2009-11-03  9:59                     ` Dmitry A. Kazakov
2009-11-05 10:38                       ` Hibou57 (Yannick Duchêne)
2009-11-05 11:00                         ` Dmitry A. Kazakov
2009-11-05 12:16                           ` Hibou57 (Yannick Duchêne)
2009-11-05 14:09                             ` Dmitry A. Kazakov
2009-11-06 12:19                               ` Hibou57 (Yannick Duchêne)
2009-11-06 13:27                                 ` Dmitry A. Kazakov
2009-10-31  2:08               ` Hibou57 (Yannick Duchêne)
2009-10-31 12:44               ` Stephen Leake
2009-11-01 11:37                 ` Dmitry A. Kazakov
replies disabled

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