* Problem with generic parameter
@ 2005-06-22 10:21 Jacob Sparre Andersen
2005-06-22 11:16 ` Martin Dowie
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jacob Sparre Andersen @ 2005-06-22 10:21 UTC (permalink / raw)
When I try to compile the program included below (cut down version of
a test program) GNAT 3.15p reports:
-----
Compiling: demo.adb (source file time stamp: 2005-06-22 10:10:41)
16. Measurement_Array => Measurement_Array);
|
>>> component subtype of actual does not match that of formal "Measurement_Array"
>>> instantiation abandoned
20 lines: 2 errors
-----
I can't see _how_ it doesn't match. Can somebody figure out what I'm
doing wrong? And maybe even suggest me an elegant solution to the
problem?
The reason I have Measurement_Array as a generic parameter is that I
also use it elsewhere, and that I may want to work with differently
indexed measurement arrays. Does it - despite that - make more sense
to declare the types "Measurement" and "Measurement_Array" together?
/Jacob
------------------------------------------------------------------------------
-- Source code:
with Generic_Root;
with Generic_Root.Child;
procedure Demo is
type Scalar is digits 15;
package Measurements is
new Generic_Root (Scalar => Scalar);
type Measurement_Array is array (Positive range <>)
of Measurements.Measurement;
package Measurement_Text_IO is
new Measurements.Child (Indices => Positive,
Measurement_Array => Measurement_Array);
begin
null;
end Demo;
generic
type Scalar is digits <>;
package Generic_Root is
---------------------------------------------------------------------------
-- type Limit:
type Limit is (Below, Exact, Above, Undefined);
---------------------------------------------------------------------------
-- type Measurement:
type Measurement (As : Limit := Exact) is
record
case As is
when Below | Exact | Above =>
Value : Scalar;
when Undefined =>
null;
end case;
end record;
---------------------------------------------------------------------------
end Generic_Root;
with Ada.Text_IO;
generic
type Indices is (<>);
type Measurement_Array is array (Indices range <>) of Measurement;
package Generic_Root.Child is
end Generic_Root.Child;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with generic parameter
2005-06-22 10:21 Problem with generic parameter Jacob Sparre Andersen
@ 2005-06-22 11:16 ` Martin Dowie
2005-06-22 11:58 ` Marius Amado Alves
[not found] ` <f6af3631a69872fe2f46258f86b08473@netcabo.pt>
2 siblings, 0 replies; 6+ messages in thread
From: Martin Dowie @ 2005-06-22 11:16 UTC (permalink / raw)
Jacob Sparre Andersen wrote:
> When I try to compile the program included below (cut down version of
> a test program) GNAT 3.15p reports:
>
> -----
> Compiling: demo.adb (source file time stamp: 2005-06-22 10:10:41)
>
> 16. Measurement_Array =>
>
> Measurement_Array); | >>> component subtype of actual does
> not match that of formal "Measurement_Array" >>>
> instantiation abandoned
>
> 20 lines: 2 errors
> -----
>
> I can't see _how_ it doesn't match. Can somebody figure out what I'm
> doing wrong? And maybe even suggest me an elegant solution to the
> problem?
Use a more compliant compiler! This works just fine with ObjectAda 7.2.2
(U18).
Actually, given that it doesn't work with GNAT GAP 1.1.0 either, I'll leave
it to a language lawyer to decide which is more compliant! :-)
Cheers
-- Martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with generic parameter
2005-06-22 10:21 Problem with generic parameter Jacob Sparre Andersen
2005-06-22 11:16 ` Martin Dowie
@ 2005-06-22 11:58 ` Marius Amado Alves
2005-06-22 13:09 ` Jacob Sparre Andersen
[not found] ` <f6af3631a69872fe2f46258f86b08473@netcabo.pt>
2 siblings, 1 reply; 6+ messages in thread
From: Marius Amado Alves @ 2005-06-22 11:58 UTC (permalink / raw)
To: comp.lang.ada
I think this is legal, so the compiler is buggy. But I find it an
unlogical generic idiom, and probably the bug has passed unnoticed
before for this reason. That is, nobody wrote this before. What I find
unlogical is the Generic_Root.Child parameters. I would find it logical
to represent the array type as an exported entity instead of a generic
parameter.
generic
type Indices is (<>);
package Generic_Root
type Measurement is array (Indices) of Measurement;
On 22 Jun 2005, at 11:21, Jacob Sparre Andersen wrote:
> with Generic_Root;
> with Generic_Root.Child;
>
> procedure Demo is
>
> type Scalar is digits 15;
>
> package Measurements is
> new Generic_Root (Scalar => Scalar);
>
> type Measurement_Array is array (Positive range <>)
> of Measurements.Measurement;
>
> package Measurement_Text_IO is
> new Measurements.Child (Indices => Positive,
> Measurement_Array => Measurement_Array);
>
> begin
> null;
> end Demo;
>
> generic
>
> type Scalar is digits <>;
>
> package Generic_Root is
>
>
> -----------------------------------------------------------------------
> ----
> -- type Limit:
>
> type Limit is (Below, Exact, Above, Undefined);
>
>
> -----------------------------------------------------------------------
> ----
> -- type Measurement:
>
> type Measurement (As : Limit := Exact) is
> record
> case As is
> when Below | Exact | Above =>
> Value : Scalar;
> when Undefined =>
> null;
> end case;
> end record;
>
>
> -----------------------------------------------------------------------
> ----
>
> end Generic_Root;
>
> with Ada.Text_IO;
>
> generic
>
> type Indices is (<>);
>
> type Measurement_Array is array (Indices range <>) of Measurement;
>
> package Generic_Root.Child is
>
> end Generic_Root.Child;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with generic parameter
[not found] ` <f6af3631a69872fe2f46258f86b08473@netcabo.pt>
@ 2005-06-22 12:43 ` Marius Amado Alves
0 siblings, 0 replies; 6+ messages in thread
From: Marius Amado Alves @ 2005-06-22 12:43 UTC (permalink / raw)
To: comp.lang.ada
I, Marius Amado Alves, just wrote:
> I think this is legal, so the compiler is buggy. But I find it an
> unlogical generic idiom, and probably the bug has passed unnoticed
> before for this reason. That is, nobody wrote this before. What I find
> unlogical is the Generic_Root.Child parameters. I would find it
> logical to represent the array type as an exported entity instead of a
> generic parameter.
>
> generic
> type Indices is (<>);
> package Generic_Root
> type Measurement is array (Indices) of Measurement;
Here's the complete 'logical' idiom, which also corrects faults above:
generic
type Indices is (<>);
package Generic_Root.Child_By_Marius is
type Measurement_Array is
array (Indices range <>) of Measurement;
end;
with Generic_Root;
with Generic_Root.Child_By_Marius;
procedure Marius_Demo is
type Scalar is digits 15;
package Measurements is
new Generic_Root (Scalar => Scalar);
package Measurements_Text_IO is
new Measurements.Child_By_Marius
(Indices => Positive);
-- now here you have your unconstrained array type
-- it is Measurements_Text_IO.Measurement_Array
-- and you have defined it only once
-- and the whole thing compiles
begin
null;
end;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with generic parameter
2005-06-22 11:58 ` Marius Amado Alves
@ 2005-06-22 13:09 ` Jacob Sparre Andersen
2005-06-22 14:26 ` Marius Amado Alves
0 siblings, 1 reply; 6+ messages in thread
From: Jacob Sparre Andersen @ 2005-06-22 13:09 UTC (permalink / raw)
Marius Amado Alves wrote:
> I think this is legal,
Thanks.
> so the compiler is buggy.
:-(
> But I find it an unlogical generic idiom, and probably the bug has
> passed unnoticed before for this reason. That is, nobody wrote this
> before. What I find unlogical is the Generic_Root.Child
> parameters. I would find it logical to represent the array type as
> an exported entity instead of a generic parameter.
>
> generic
> type Indices is (<>);
> package Generic_Root
> type Measurement is array (Indices) of Measurement;
The reason that I don't do that is that that would have to instantiate
a copy of Generic_Root _and_ Generic_Root.Child for each choice of
array indices.
I will report the problem to ACT and Debian. - And use your suggestion
as a workaround.
Jacob
--
Would you also prefer not to have had to read Victor Hugo?
Vote for EU software patents!
http://www.guardian.co.uk/online/comment/story/0,12449,1510566,00.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with generic parameter
2005-06-22 13:09 ` Jacob Sparre Andersen
@ 2005-06-22 14:26 ` Marius Amado Alves
0 siblings, 0 replies; 6+ messages in thread
From: Marius Amado Alves @ 2005-06-22 14:26 UTC (permalink / raw)
To: comp.lang.ada
>> generic
>> type Indices is (<>);
>> package Generic_Root
>> type Measurement is array (Indices) of Measurement;
>
> The reason that I don't do that is that that would have to instantiate
> a copy of Generic_Root _and_ Generic_Root.Child for each choice of
> array indices.
No you don't. (The above example was misleading.)
generic
type Indices is (<>);
package Generic_Root.Child_By_Marius is
type Measurement_Array is
array (Indices range <>) of Measurement;
end;
with Generic_Root;
with Generic_Root.Child_By_Marius;
procedure Marius_Demo is
type Scalar is digits 15;
package Measurements is
new Generic_Root (Scalar => Scalar);
package Measurements_Text_IO is
new Measurements.Child_By_Marius
(Indices => Positive);
use Measurements_Text_IO; --|
Array_1 : Measurement_Array (1 .. 10); --| *HERE*
Array_2 : Measurement_Array (2 .. 20); --|
begin
null;
end;
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-06-22 14:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-22 10:21 Problem with generic parameter Jacob Sparre Andersen
2005-06-22 11:16 ` Martin Dowie
2005-06-22 11:58 ` Marius Amado Alves
2005-06-22 13:09 ` Jacob Sparre Andersen
2005-06-22 14:26 ` Marius Amado Alves
[not found] ` <f6af3631a69872fe2f46258f86b08473@netcabo.pt>
2005-06-22 12:43 ` Marius Amado Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox