I would like to program a ring object, and am having problems getting started. Something like
type Data = Pointer; // ???
class TRing
Zero: Data;
function Sum(Data, Data): Data; abstract;
function Product((Data, Data): Data; abstract;
end;
The idea is to instantiate the functions Sum and Product later
to special cases where the ring elements are Real, Integer, Rational,
Real Polynomials, Complex,..
For a concrete problem, think of adding two vectors with elements in the ring. I want to write the code only once, not repeat it for each kind of ring element:
type TVector = record
Dim: Cardinal;
Coord: array of Data;
function VectorSum(V, W: Vector): Vector;
var K: Cardinal;
begin
with Result do
begin
Dim := V.Dim;
SetLength(Coord, Dim);
for K := 0 to Dim - 1 do
Coord[K] := Sum(V.Coord[K], W.Coord[K]);
end;
end;
(Please ignore missing and incorrect details.) I need help with the OOP
aspects of doing something like this.
Of course I have more ambitious things in mind, like matrix multiplication.
If you have any ideas on how to go about this, please contact me at
harley@umich.edu. Thank you.