You can make the generic formal parameter a private type. This
allows it to be instantiated with any type for which assignment
and test for equality are predefined. You would want to have a
set of numeric parameters for the type so you can make it
useful. For example,
type Item is private;
with function "+" (L, R : Item) return Item is <>;
-- with similar parameters for all other numeric operators
with function "<" (L, R : Item) return Boolean is <>;
-- with similar parameters for other relational operators
with function Zero_Equivalent return Item;
with function Tic_First return Item;
with function Tic_Last return Item;
-- The preceding functions are useful for numeric and non numeric
-- instantiations of private types
package FooFoo is
-- some stuff for making the package work,
You might also look at the example using generic formal pacakge parameters
in my article in the last issue of Ada Letters.
[log in to unmask]
AdaWorks Software Engineering
2555 Park Boulevard
Palo Alto, CA 94306
On Mon, 7 Dec 1998, Igor Izvarin wrote:
> Hello to everybody,
> 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(...);
> 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:
> type COEFFICIENT is ???????
> package ...
> Sorry for my stupid questions. I am novice in Ada programming.
> Thank you for your time and help!
> With best regards, Igor Izvarin.