Rationale for Ada 2005

John Barnes
Table of Contents   Index   References   Search   Previous   Next 

9.3.2 Partial generic instantiation

Certain attempts to use signature packages lead to circularities. The AI (AI-359) outlines the following example 
generic
   type Element is private;
   type Set is private;
   with function Union(L, R: Set) return Set is <>;
   with function Intersection(L, R: Set) return Set is <>;
   ... -- and so on
package Set_Signature is end;
Remember that a signature is a generic package consisting only of a specification. When we instantiate it, the effect is to assert that the actual parameters are consistent and the instantiation provides a name to refer to them as a group.
If we now attempt to write 
generic
   type Elem is private;
   with function Hash(E: Elem) return Integer;
package Hashed_Sets is
   type Set is private;
   function Union(L, R: Set) return Set;
   function Intersection(L, R: Set) return Set;
   ...
   package Signature is new Set_Signature(Elem, Set);
private
   type Set is
      record
         ...
      end record;
end Hashed_Sets;
then we are in trouble. The problem is that the instantiation of  Set_Signature tries to freeze the type Set prematurely.
Other similar examples concern the use of access types with private types. The essence of the problem is that we want to instantiate a package with a private type before the full declaration of that type.
The solution proposed was to split an instantiation into two parts, a partial instantiation and a full (that is, normal) instantiation. The partial instantiation might take the form 
package P is new G(Private_Type) with private;
and this can be done with the partial view of the type. The full instantiation can then be given after the full declaration of the type.
This fell by the wayside at the last minute largely because of fears that awkward situations might be introduced inadvertently.

Table of Contents   Index   References   Search   Previous   Next 
© 2005, 2006 John Barnes Informatics.
Sponsored in part by:
The Ada Resource Association and its member companies: ARA Members AdaCore Polyspace Technologies Praxis Critical Systems IBM Rational Sofcheck and   Ada-Europe:
Ada-Europe