A truly polymorphic number class hierarchy


Aleksandar Popović, Mirjana Ivanović




A class hierarchy for numbers has been implemented in Modula-3. The hierarchy starts with an abstract number class that encompasses common operations for all numbers and ends with concrete classes for integer, rational, real and complex numbers. All numbers have been implemented in ordinary and arbitrary precision. The paper, however, emphasizes the polymorphic nature of the hierarchy. Using the hierarchy it is possible to build procedures and functions that are truly independent of its argument types or function results. To achieve this, several additional procedures had to be implemented using low-level facilities.