One of the nice thing about genericity in Ada is that it is by its very nature constrained. When you define generic paramters you must, in effect, tell the compiler and the human code reader, what is required of the types passed as generic parameters. This is great for readability, but is also useful - naturally - for compile time checking and optimization.
This paper discusses the notion of constrained genericity in more detail.
Most object oriented languages don't support constrained genericity directly. Some don't support it at all.
Consider a sort<T> routine in C++. T must support a comparison routine <. However, this is unclear from the routines generic signature. The compiler may deduce, for example, the T must derive from a Comparable type, but this realization itself can only be achieved by compiling the routines implementation.
In Ada, the compiler would be able to compile the routine's declaration (spec), and then independently of the routine's implementation be able to check the correctness of instantiations of the routine (i.e., the T has the required comparison function).
It seems to me, but perhaps I am mistaken, that the disciplined apporach to constrained genericity isn't popular these days. The C++ approach is problematic, and it seems the proposals for adding genericity to Java and C#, folow the same path.
Posted to theory by Ehud Lamm on 6/30/01; 10:29:27 PM
|
|