comp.lang.ada
 help / color / mirror / Atom feed
From: jpwoodruff@irisinternet.net (John Woodruff)
Subject: Two generic families: I'm confused by error msg
Date: 2 Nov 2004 21:40:29 -0800
Date: 2004-11-02T21:40:29-08:00	[thread overview]
Message-ID: <34defe4d.0411022140.17304b1c@posting.google.com> (raw)

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 ;


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) ;

begin
   null ;
end Unreal ;



             reply	other threads:[~2004-11-03  5:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-03  5:40 John Woodruff [this message]
2004-11-03  8:46 ` Two generic families: I'm confused by error msg Dmitry A. Kazakov
2004-11-03 10:01 ` Martin Dowie
2004-11-03 13:37   ` Georg Bauhaus
2004-11-05  3:45   ` John Woodruff
replies disabled

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