Polysemous Values Qustion
Nathan Reed
nathaniel.reed at gmail.com
Tue Sep 25 21:28:06 PDT 2007
Robert Frser wrote:
> Can someone giv me an example where polysemous values could apply to a class (given the class has (multiple) opImplicitCastTo/From)
Here's another example where polysemous values could come in handy:
interface A { ... }
interface B { ... }
class Foo : A, B { ... }
class Bar : A, B { ... }
void main (string[] args)
{
bool flag = ...
auto whatsMyType = flag ? new Foo : new Bar;
}
Here, Foo and Bar both implement A and B, so the variable 'whatsMyType'
could have either type A or type B. If you do this in D now, it will
fail with a compile error, since Foo and Bar have no least upper
bound...but with polysemous values, whatsMyType could have type "A or B".
Thanks,
Nathan Reed
More information about the Digitalmars-d
mailing list