[comp.lang.ada] Instantiating Ada Generic Packages

paul@batserver.cs.uq.oz.au (Paul Bailes) (03/29/90)

Dear colleagues,

I have a problem with Ada generics. Consider the following situation:

	package A is

		type B is <C.D>;

		package C is is new E (B);

	end;

and

	generic

		type F is private;

	package E is

		type D is private;

	private

		type G;
		type D is access G;

	end;

with

	package body E is

		type G is <F>

	end;

(the notation <X> means a code fragment including X)

The problem is that type B depends upon C.D, which itself comes
from the instantiation of E with B - a potential circularity, that
is forbidden by Ada - the above code is (I think) illegal, because
the <C.D> in package A precedes the declaration of C (by the
instantiation of E).

However, the circularity is not an objective problem because C.D
is only an access to the use of B (formal parameter F used in
full type declaration of private G to which D is an access).

From a language designer's point of view, one could imagine a development
of Ada that separated the instantiation of a generic package spec. from
that of the corresponding body: the above would then appear of some form
in which the package spec. instantiates only the generic spec:

	package A is

		package C is new E (any actual params for the spec. only);

		type B is <C.D>;

	end;

plus a body that instantiates the generic body:

	package body A is

		package body C is new E (B);

	end;

plus the generic spec. with spec.-only parameters:

	generic

		any formal params for the spec. only

	package E is

		type D is private;

	private

		type G;
		type D is access G;

	end;

plus the generic body that needs actual param B (from the 1st package spec.)

	generic

		type F is private;

	package body E is

		type G is <F>

	end;

My questions are

	(1) is my perception of my problem a correct one?

	(2) why doesn't Ada have separate instantiation of
	    generic package specs. and bodies?

	(3) how can I do what I want WITHOUT having to
	    expand the generic ``by hand'', in effect to
	    achieve the separation of instantiations of
	    specs. and bodies that I desire?

I look forward to reading your solutions on the news!

Thanks in advance,
Paul A. Bailes
Dept. Computer Science
University of Queensland QLD 4072
Australia

mfeldman@seas.gwu.edu (Mike Feldman) (03/29/90)

Aaaaahhhhhhhhh.......

a technical question! At last!

Sorry I can't answer it right off the bat, but I sure am grateful that
you asked it!