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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3039151bd3ba684d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Two generic families: I'm confused by error msg Date: Wed, 3 Nov 2004 09:46:29 +0100 Message-ID: <5swbuhbigx4j.11nuugld4168.dlg@40tude.net> References: <34defe4d.0411022140.17304b1c@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de yBdgw+K8HIeSTZJwruhTLQ5jLSLN6u2N4eeQ0j1QNIloCsfx4= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5975 Date: 2004-11-03T09:46:29+01:00 List-Id: On 2 Nov 2004 21:40:29 -0800, John Woodruff wrote: > I'm puzzled by an Ada error. The error arises in the attached > program, which uses two different (parent-child) pairs of generic > packages. And the error seems to indicate a hard-for-me-to-understand > issue of visibility. > > The first two packages (numeric_io and it's child *.matrix_io) do some > IO on vectors and matrices of floating numbers. Just about like the > new Ada.Numerics.Generic_Real_Arrays.Generic_IO. > > Two more packages (name_io and its child *.matrix_name_io) add > services that parse name-directed input for object-oriented > applications. This pair uses instances of numeric_io, so that vectors > are the same regardless of which services are invoked. > > It all works fine, and I'm in the final stages of preparing this to > share. Maybe on adaworld or adapower if they'll have me.... > > BUT > > Numeric_io defines a subtype "real" that is just the actual type given > for its argument. That's how the two children manage to work on the > same types (they are children of different, unrelated, parents). > > So along comes the client (I named it "Unreal" in this exhibit). It > laces the two generic families together, and it works perfectly IF and > ONLY IF it *happens* to use the identifier "Real" somewhere. This > client does not need to declare any *usage* of the subtype "Real", nor > use it in instantiating the generics. > > Unfortunately, poor client has no way of knowing he needs to declare > "real". And I'm not sure what is the language-law that connects the > type Scalar_IO.Real in the generic actual package with the subtype > identifier Real in the client. > > Can someone help me make sense of this? Can someone suggest a way to > rephrase these relationships so I don't require the client to "say the > magic word"? > > <<< gnatchop the stuff after this line to see the puzzle >>> > > generic > type Floating_Type is digits <> ; > package Numeric_Io is > subtype Real is Floating_Type ; > end Numeric_Io ; > > > generic > type Vector_Ix is (<>) ; > type Vector is array (Vector_Ix range <>) of Real ; > package Numeric_Io.Matrix_IO is > end Numeric_Io.Matrix_IO ; > > with Numeric_Io; > generic > type Floating_Type is digits <> ; > with package Scalar_Io is new Numeric_Io (Floating_Type) ; > package Name_Io is > end Name_Io; > > with Numeric_Io.Matrix_Io ; > generic > type Vector_Ix is (<>) ; > type Vector is array (Vector_Ix range <>) of Scalar_Io.Real ; > with package Matrix_Io is new Scalar_Io.Matrix_Io > (Vector_Ix, Vector) ; > package Name_Io.Matrix_name_IO is > end Name_Io.Matrix_name_IO ; Why do not you do it as: with Numeric_Io.Matrix_Io ; generic with package Matrix_Io is new Scalar_Io.Matrix_Io (<>); package Name_Io.Matrix_name_IO is Here you can refer the actual types of Matrix_IO instantiation as Matrix_IO.Vector_Ix and Matrix_IO.Vector. This would also make instantiations easier. > with Numeric_Io.Matrix_Io ; > with Name_Io.Matrix_Name_Io ; > > procedure Unreal is > type Unreal is digits 6 ; > > -------------------------------------------------------------------------- > -- If this line "subtype Real is Unreal" is ABSENT, then error at line 26: > -- Component subtype of actual does not match that of formal "Vector" > -------------------------------------------------------------------------- > subtype Real is Unreal; > > type Vector is array (Integer range <>) of Unreal ; > > package Scalar_IO is new Numeric_IO (Unreal) ; > > package Matrix_IO is new Scalar_IO.Matrix_IO > (Vector_Ix => Integer, > Vector => Vector); > > package Nio is new Name_Io (Floating_Type => Unreal, > Scalar_Io => Scalar_IO); > > package Mat_IO is new Nio.Matrix_Name_IO > (Vector_Ix => Integer, > Vector => Vector, -- the error is here > Matrix_Io => Matrix_IO) ; Yes, I saw that problem too and many times. To me it looks like a compiler bug, but wait what our language lawyers will say. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de