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/18 Message-ID: <37baefa0@news1.us.ibm.net>#1/1 X-Deja-AN: 514290585 Content-transfer-encoding: 7bit References: <37b9ac3d@news1.us.ibm.net> X-Trace: 18 Aug 1999 17:38:40 GMT, 32.101.8.66 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-18T00:00:00+00:00 List-Id: In article , tmoran@bix.com wrote: > with Fruit, Fruit.Apple_Sets, Fruit.Orange_Sets; The statement with Fruit.Apple_Sets, Fruit.Orange_Sets; will do. > package Getting_Complicated is > function Prettier_Than(X : Fruit_Type) return Fruit.Apple_Sets.Pile; > function Prettier_Than(X : Fruit_Type) return Fruit.Orange_Sets.Pile; > ... > It seems unreasonable that it should be so much trouble just to > declare a simple *homogenous* array. Then perhaps you overcommitted. Your access type is a pointer to a specific kind of fruit (Apple_Ptr, Orange_Ptr, etc). This gives you a static guarantee about the specific type designated by the access object. If you don't need that much to be known statically, then you can loosen up the types by simply using an access type that designates Fruit_Type'Class. You wouldn't even need the generic anymore. You make the rule ("precondition") that it's up to the client to make sure that the array is populated by only one type. > I understand that the compiler has a probem with an array when it doesn't yet > know the size of its elements, but here the elements are all pointers, so that > isn't a problem. Then just make an array of type Fruit_Access is access all Fruit_Type'Class; type Fruit_Array is array (Positive range <>) of Fruit_Access; You can then write functions like: function Apples_Prettier_Than (X : Fruit_Type) return Fruit_Array; with a postcondition that all components of the return value are of specific type Apple_Type; and function Oranges_Prettier_Than (X : Fruit_Type) return Fruit_Array; with a postcondition that all components of the return value are of specific type Orange_Type. Remember that not all constraints have to be satisfied statically by the compiler (by using pointers to specific types). Use pointers to the class-wide root, and specify pre- and post- conditions about the nature of the actual specific type designated. -- 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"