[asked Igor]
>
> I continue to ask questions!
>
> Now I am writing the package working with polynomials:
>
> Package POLYNOMIAL_PACKAGE is
> Type POLYNOMIAL is private;
> Procedure Print(...);
> Procedure Dump(...);
> ...
> private
> ...
> end POLYNOMIAL_PACKAGE;
>
> but I want to use polynomials with integer and floating coefficients. HOW
> CAN I MAKE A GENERIC PACKAGE TO WORK WITH DIFFERENT TYPES OF COEFFICIENTS:
>
> generic
> type COEFFICIENT is ???????
> package ...
> ...
> end;
>
> Sorry for my stupid questions. I am novice in Ada programming.
>
You'd write
type Coefficient is private;
which allows any actual type such that := and = are predefined.
There is not a way to write "any numeric type of coefficient", so in
some sense this one is too general, but in fact one could use
this to advantage. For example, if you had written a package for
rational arithmetic (say, storing a rational in a record as a
numerator/demominator pair), you could instantiate your polynomial
package for _rational_ coefficients.
My data structures book
Feldman, M.B.
Software Construction and Data Structures with Ada 95
Addison-Wesley, 1997. ISBN 0-201-88795-9
http://www.awl.com/cseng/titles/0-201-88795-9/
has some examples of this kind of generic
package. All the code examples from the book - nearly 200 compilable
units of different kinds - are online at
ftp://ftp.seas.gwu.edu/pub/ada/courses/cs2code.*
there are several different archive formats there. The archive
contains an index that relates the book program numbers to the
unit names, so if you examine the programs in sequence, you
can probably follow them without having the book.:-)
Mike Feldman