3 ms·
How else would you implement addition? What is another API that can handle adding objects of various types, (Int8,16,32,64, BigInt, Complex for all of these, ra
by adgjlsfhk1 5y ago
How else would you implement addition? What is another API that can handle adding objects of various types, (Int8,16,32,64, BigInt, Complex for all of these, rational for all of these, and Float16, 32, 64) that doesn't totally suck?
- recursivedoubts 5y agounion types
- DNF2 5y agoFirst of all, Julia does have union types. But how does that help when the caller gives you a user-defined type?
- recursivedoubts 5y agow/ proper union types, you just chuck another type, user defined or not, in the method signature and type cast via whatever syntax you have available in the implementation
- DNF2 5y agoSo you live in a world where there's a fixed number of built-in types hard-coded into your library? I'm afraid that doesn't cut it in a modern programming context.
- adgjlsfhk1 5y agothat only works if the method knows about all the types that might exist. The reason overloading is necessary is that the person that writes + for your programming language doesn't know all the types that people will want to call + on. As such, you need a way to define new implementations of + when people add new types in the future. This forces you to have some form of overloading.