I am a reasonably experiences hobby programmer, and I have good familiarity with C++, D, Java, C# and others.
With the exception of Go, almost every language requires me to explicitly state that I am implementing an interface. This is borderline ridiculous, since we today have compilers for languages like Haskell, which can do almost full-program type inference with very few hints.
What I am looking for is a programming language that does this:
interface ITest {
void Test();
}
class Test {
void Test() { }
}
void main() {
ITest x;
x = new Test;
}
What languages would see this, and automatically flag Test
as implementing ITest
?
ETA: I am not looking for duck typing. I am looking for strictly typed languages with inference.
D has something called wrap
in its standard library, Phobos, which can do what you're looking for. Here's an example copied from the function's unittest:
interface A {
int run();
}
interface B {
int stop();
@property int status();
}
class X {
int run() {
return 1;
}
int stop() {
return 2;
}
@property int status() {
return 3;
}
}
auto x = new X();
auto ab = x.wrap!(A, B);
A a = ab;
B b = ab;
assert(a.run() == 1);
assert(b.stop() == 2);
assert(b.status == 3);
The work will be available starting from v2.064, and it is already on git HEAD.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With