Rationale for Ada 2012

John Barnes
Contents   Index   References   Search   Previous   Next 

9.3.2 Partial generic instantiation

Certain attempts to use signature packages led to circularities in Ada 95. Consider
   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
   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);
   type Set is
      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.
After a number of false starts this problem is partially overcome in Ada 2012 by the introduction of incomplete formal generic parameters. This is discussed in Section 4.3 of the chapter on Structure and Visibility. See also Section 9.4.1 of this chapter.

Contents   Index   References   Search   Previous   Next 
© 2011, 2012, 2013 John Barnes Informatics.
Sponsored in part by:
The Ada Resource Association:


and   Ada-Europe: