comp.lang.ada
 help / color / mirror / Atom feed
From: jankok@cwi.nl (Jan Kok)
Subject: Re: GNAT error messages, strange generic construction
Date: 1995/04/07
Date: 1995-04-07T00:00:00+00:00	[thread overview]
Message-ID: <D6noLx.Fyu@cwi.nl> (raw)
In-Reply-To: 3m10hi$eu0@nyheter.chalmers.se

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                     |      '   /_




  reply	other threads:[~1995-04-07  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-04-06  0:00 GNAT error messages, strange generic construction Anders H Johansson
1995-04-07  0:00 ` Jan Kok [this message]
1995-04-07  0:00 ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox