On 12/15/10 11:49 AM, Robert Jacques wrote:
[JSON]

Apologies for not making the time to review this; I'm very interested in the topic but I have 121 emails waiting for attention in my inbox, and each requires a fair amount of work.

Notes:
* Does anyone have a suggestion of a good way to attach methods to an
Algebraic type? And if we can, should we?

This is a very good challenge. Ideally Algebraic would define a method if and only if all of its possible types define a method with (a) same name, (b) covariant return types (i.e. return types have a CommonType), (c) contravariant parameter types (we don't have ContravariantCommonType in std.traits, but it should be doable). Consider:

class Widget {
    long foo(int);
}

class Gadget {
    int foo(long);
}

auto a = Algebraic!(Widget, Gadget)(new Widget);
long x = a.foo(42); // should work
x = a.foo(x); // shouldn't compile

That would be awes, and is in fact implementing an optimization called type casing.


Andrei

Reply via email to