TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
X-To:
Igor Izvarin <[log in to unmask]>
Date:
Mon, 7 Dec 1998 15:40:15 -0800
Reply-To:
AdaWorks <[log in to unmask]>
Subject:
From:
AdaWorks <[log in to unmask]>
In-Reply-To:
Content-Type:
TEXT/PLAIN; charset=US-ASCII
MIME-Version:
1.0
Parts/Attachments:
TEXT/PLAIN (71 lines)
Igor,

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,

     generic
       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,
    end FooFoo;

  You might also look at the example using generic formal pacakge parameters
  in my article in the last issue of Ada Letters.

  Richard

Richard Riehle
[log in to unmask]
AdaWorks Software Engineering
Suite 30
2555 Park Boulevard
Palo Alto, CA 94306
(650) 328-1815
FAX  328-1112
http://www.adaworks.com

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(...);
> ...
> 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.
>
> Thank you for your time and help!
>
> With best regards, Igor Izvarin.
>

ATOM RSS1 RSS2