The current |
Since 2006, the structure of
The current type system also comes with a few improvements. First of all, it is now possible to define automatic converters. Such converters can be combined according to transtivity properties which may be declared by the user. Secondly, the new type system provides a generic type Generic, together with an automatic converter T -> Generic for any type T.
The mixture of a generic type with conventional strongly typed system raises some subtle, but interesting, questions:
One has to be careful with automatic conversions: using converters T -> Generic and Generic -> Vector Generic, and similarly for Matrix Generic, Series Generic, etc., any type T can be converted into Vector Generic. In particular, when implementing operations on Vector Generic, one should avoid conversions of the scalars to Vector Generic, which may cause infinite loops.
Currently, the above problem is solved by attaching penalties to converters (and penalties are combined using max rather than +). The converter Generic -> Vector Generic is used only if all other methods fail. However, we are generally not in favour of systems which are based on priorities. We intend to invent something cleaner in the future.
One of the reasons behind having a Generic type is to gracefully combine a high level user interface with a powerful programming language. However, these two objectives sometimes conflict. For instance, consider the example 2*(3/2); what should the return type be? The end-user sees 3 and will assume the result to be an Integer. However, from the programming point of view, returning a Rational makes it possible to design more systematic algorithms.
Our current view on the above problem is to allow for both possibilities: programmers may use a strongly typed language in which 2*(3/2) will explicitly be considered to be a Rational. End-users rather rely on the Generic type and printing 2*(3/2) will imply an automatic conversion Rational -> Generic, which may actually simplify the rational into an integer. This mechanism has not been implemented and tested yet, but we hope to do this sometime soon.