From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f24afa16a58c409 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: premature use of private Date: 1999/08/17 Message-ID: <37b9ac3d@news1.us.ibm.net>#1/1 X-Deja-AN: 513892405 Content-transfer-encoding: 7bit References: X-Trace: 17 Aug 1999 18:38:53 GMT, 32.101.8.24 Organization: Global Network Services - Remote Access Mail & News Services X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset="US-ASCII" Mime-version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: postmaster@ibm.net Date: 1999-08-17T00:00:00+00:00 List-Id: In article , tmoran@bix.com wrote: > So far so good. But I don't want a Pile of mixed Fruit, so, > borrowing from Barnes' on Containers, I tried: > > generic > type This_Fruit is abstract tagged private; > type Fruit_Ptr is access all This_Fruit; > package Sets is > type Pile is array(integer range <>) of Fruit_Ptr; > procedure Sort_By_Size(X : in out Pile); > end Sets; > > type Apple_Ptr is access all Apple; > package Apples is new Sets(Apple, Apple_Ptr); > > But that won't work because Apple is private at this point. > > How should this be done? In order to instantiate the package, you need the full view of the type. I would declare the instantiations as children of the package in which the type is declared, e.g.: package Fruit is type Fruit_Type is ...; type Apple_Type is new Fruit_Type with private; type Apple_Ptr is access all Apple_Type; ... end Fruit; generic type This_Fruit is abstract tagged private; --or type This_Fruit is new Fruit_Type with private; type Fruit_Ptr is access all This_Fruit; --or, rather than importing the access type as a generic formal type, --just declare it locally, in the spec of Sets. package Fruit.Sets is type Pile is array(integer range <>) of Fruit_Ptr; procedure Sort_By_Size(X : in out Pile); end Fruit.Sets; Now, for the instantiation: with Fruit.Sets; package Fruit.Apple_Sets is new Fruit_Sets (Apple_Type, Apple_Ptr); If you go with the child package idea (suggested by David Hoos), then you structure the hierarchy as: package Fruit is type Fruit_Type is abstract tagged private; ... end Fruit; package Fruit.Apples is type Apple_Type is new Fruit_Type with private; type Apple_Ptr is access all Apple_Type; -- or Apple_Type'Class ... end Fruit.Apples; with Fruit.Sets; package Fruit.Apples.Sets is new Fruit.Sets (Apple_Type, Apple_Ptr); You don't have to cram the entire world in one package -- break it up into a package hierarchy. The idea is to always submit as little program text to the compiler as possible. -- Matt It is impossible to feel great confidence in a negative theory which has always rested its main support on the weak points of its opponent. Joseph Needham, "A Mechanistic Criticism of Vitalism"