Lambda the Ultimate

inactiveTopic Constrained Genericity
started 6/30/2001; 10:29:17 PM - last post 6/30/2001; 10:47:05 PM
Ehud Lamm - Constrained Genericity  blueArrow
6/30/2001; 10:29:17 PM (reads: 2036, responses: 1)
Constrained Genericity
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

Ehud Lamm - Re: Constrained Genericity  blueArrow
6/30/2001; 10:47:05 PM (reads: 1107, responses: 0)
A bit more information.

PolyJ is a Java genericity proposal, that does support constrained genericity (it is based on the concept of where clauses, explained in the paper mentioned in my original post). Other Java genericity proposals.

Meyer on Genericity in the OO Context.