equivariant functions

Yigal Chripun yigal100 at gmail.com
Thu Oct 16 23:41:36 PDT 2008


Andrei Alexandrescu wrote:
> Anyhow, I wanted to share one more thought. On the face of it, as
> someone already said, we DO have a solution to avoid code duplication:
> templates. Maybe a fertile direction to take would be to use regular
> template syntax and just let the compiler figure out that it can
> actually define only one function instead of three.

here's a stab at a syntax similar to templates:

T func(x : const, y : const)(X x, Y y, const Z z);

in the above the return type T constancy is dependent on the constancy
of x and y. z is a "regular" const.
the idea is that X's *constancy* (not the entire type!) is subtype of
const.

here's a method:

class Klass {
    T met(this: const, y : const)(X x, Y y, const Z z);
}

generic min function would look like:
T min(T, x : const, y : const) (T x, T y) { ...}

what do you think?



More information about the Digitalmars-d mailing list