When B
tries to call A
, how is it going to know which A
? What is the type Input
to be?
Usually, you’d solve this by including all of A
, B
and C
in a generic package;
package P is
generic
type Input is private;
package G is
procedure A (X : Input);
procedure B;
procedure C;
end G;
end P;
If you need the structure you’ve shown, you have to write
generic
type Actual_Input is private;
with procedure Actual_A (X : Actual_Input);
procedure B;
and then instantiate by
procedure My_A is new P.A (Input => Integer);
procedure My_B is new P.B (Actual_Input => Integer, Actual_A => My_A);
In a different language, formal subprograms would be like formal packages and you could write something like
generic
type Actual_Input is private;
with procedure Actual_A (X : Actual_Input) is new A (Input => Actual_Input);
procedure B;
to make sure that the Actual_A
was in fact an instance of A. But that’s not Ada.