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=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,449670964aa111f5 X-Google-Attributes: gid103376,public From: jankok@cwi.nl (Jan Kok) Subject: Re: GNAT error messages, strange generic construction Date: 1995/04/07 Message-ID: #1/1 X-Deja-AN: 100070328 sender: news@cwi.nl (The Daily Dross) references: <3m10hi$eu0@nyheter.chalmers.se> organization: CWI, Amsterdam newsgroups: comp.lang.ada Date: 1995-04-07T00:00:00+00:00 List-Id: In article <3m10hi$eu0@nyheter.chalmers.se> m88asjn@mtek.chalmers.se (Anders H Johansson) writes: > ... > >2. What's the point of this generic package construction (mentioned > e.g. in J.G.P Barnes "Programming in Ada", p. 447-448): > > with Generic_Elementary_Functions; > with Generic_Complex_Numbers; > generic > with package Elementary_Functions is > new Generic_Elementary_Functions(<>); > with package Complex_Numbers is > new Generic_Complex_Numbers(Elementary_Functions.Float_Type); > package xxx is > . > . >I think it would be more reasonable to transform the generic package parameter >Complex_Numbers into an ordinary instantiation, placed inside the package >xxx. Since it is already decided how it will be instantiated, the genericity >fills no function?! > >package xxx is > package Complex_Numbers is > new Generic_Complex_Numbers(Elementary_Functions.Float_Type); > >--------- My short answer to this question is: it is a simple and legal way to make sure that the user of xxx can use the same type (for complex numbers) that the package xxx is using internally. I can elaborate: 1. A possible reason that I will not discuss: as this is a text book, the example serves to illustrate some language features. 2. We may expect that a package (like xxx) that does complex arithmetic (through the instance Complex_Numbers) is used by someone who has complex_type data. a) If the instantiation of Generic_Complex_Numbers is made inside xxx, then the user could have obtained a type for his/her complex data through a separate instantiation of Generic_Complex_Numbers. The types will not be the same, so what can one do to make the external complex data available to xxx. Several solutions (component wise, for example) but not attractive. b) Or: xxx is providing a type Complex whose declaration is derived from the instance Complex_Numbers. If another package yyy is also using complex arithmetic, it will have to repeat the instantiation and also make a type yyy.Complex available. How does the user convert from xxx.Complex to yyy.Complex? Again not nice. It is true that the user has to do the instantiation of Generic_Complex_Numbers, but that is what gives the type Complex. I prefer Barnes' design. This example does not allow a user-made package for complex arithmetic to be imported in xxx, but that is fine with me. -- --Jan Kok | =#===-=========##= Mail: CWI (dpt. NW) | -- ,___@ P.O.Box 94079/NL-1090 GB Amsterdam | -- __/\ E-mail: Jan.Kok@cwi.nl | ' /_