-- This example has three compilation units : -- The generic package specification for GENSUMPKG -- The package body for GENSUMPKG -- The test procedure that instantiates GENSUMPKG with -- generic actual parameters INTEGER and MY_ARRAY generic -- gensumpkg.ads type ELEMENT is private ; type KEY_1 is array ( INTEGER range <> ) of ELEMENT ; with function "+" ( U , V : ELEMENT ) return ELEMENT is <> ; package GENSUMPKG is procedure SUM ( A : in out KEY_1 ) ; end GENSUMPKG ; -- end of first compilation unit package body GENSUMPKG is -- gensumpkg.adb procedure SUM ( A : in out KEY_1 ) is TOTAL : ELEMENT := A ( A'FIRST ) ; -- no numbers allowed begin for I in A'FIRST + 1 .. A'LAST loop TOTAL := TOTAL + A ( I ) ; end loop ; A ( A'FIRST ) := TOTAL ; end SUM ; end GENSUMPKG ; -- end of second compilation unit with TEXT_IO ; use TEXT_IO ; -- testgens.adb with GENSUMPKG ; procedure TEST_GENSUMPKG is type MY_ARRAY is array ( INTEGER range <> ) of INTEGER ; STUFF : MY_ARRAY ( 1 .. 3 ) := ( 1 , 2 , 3 ) ; package INT_IO is new INTEGER_IO ( INTEGER ) ; use INT_IO ; -- This is the generic instantiation of the package above package MY_SUM is new GENSUMPKG ( ELEMENT => INTEGER , KEY_1 => MY_ARRAY ); --or package MY_SUM is new GENSUMPKG ( INTEGER , MY_ARRAY ) ; -- positional use MY_SUM ; -- optional, could also write MY_SUM.SUM below begin PUT_LINE ( " GENERIC SUM PACKAGE " ) ; SUM ( STUFF ) ; -- call procedure in instantiated package PUT ( STUFF( 1 )) ; PUT_LINE ( " = SUM " ) ; end TEST_GENSUMPKG ; -- GENERIC SUM PACKAGE \___results of running. -- 6 = SUM /