| ▲ | one-punch 3 hours ago | ||||||||||||||||||||||
You have implemented a form of ‘ad-hoc polymorphism’. This is different from ‘parametric polymorphism’, which is what people call generics. | |||||||||||||||||||||||
| ▲ | Someone 2 hours ago | parent [-] | ||||||||||||||||||||||
I somewhat disagree. FTA: “If the callsite is some_function(2);, the compiler resolves T as i32 and selects the corresponding branch, returning the value incremented by one. […] The important point is that the decision is driven entirely by type information, not by runtime inspection” Given that, this isn’t that different from C generics (https://en.cppreference.com/w/c/language/generic.html), and people call that generics, too. Having said that, even ignoring that this requires all implementations to be in a single source file (yes, you probably could use m4 or #include or whatever it’s called in this language) I do not find this syntax elegant. Also, one thing that it doesn’t seem to support is generating compiler errors when calling a function with a type that isn’t supported. | |||||||||||||||||||||||
| |||||||||||||||||||||||