I'd like to test the waters of writing Ada packages by making one for manipulating polynomials. Polynomials can be defined for a wide class of algebraic structures, so to reflect this, I'd like to make the package generic, so it can be used with Floats, Integers, or other numeric sub-types.
I want to say now that I know very little about how Ada's type system work or how its package system works. There seems to be a lack of good beginner Ada inforamtion on the web, so I'm having to glean what wisdom I can from this not-so-newbie-friendly Wikibooks article.
This page has some information about the type hierarchy. Based on that, it would seem that a reasonable type for my Polynomial package to be based on would be the Scalar type, since apparantly that's the one on which arithmetic operations are defined. So this is what I've attempted, in polynomials.ads:
generic
MAX_DEGREE : Positive;
type Element is new Scalar;
package Polynomial is
type Polynomial is Array (0 .. MAX_DEGREE) of Element;
end Polynomial;
However, this just nets me a "Scalar" is undefined error from GNAT.
So far I've really just been feeling my way around half-blind, I don't actually know how any of this stuff works. If I seem to have any major misconceptions that you think need to be cleared up, please tell me. Probably the easiest would be to provide example polynomial.ads and polynomial.adb code that I can learn from - just like a definition of the Polynomial type (with generic max-degree and element type) and a simple example function like adding two polynomials, so I can see how generic functions work.
PS: Sort of related, is there a way to define attributes for your user-defined types?