3 ms·
> It does not matter if the vtable used to map a function call to the chosen type-specific overload occurs in an otherwise dynamically typed language or not, it
by stabbles 6y ago
> It does not matter if the vtable used to map a function call to the chosen type-specific overload occurs in an otherwise dynamically typed language or not, it’s just your grandpa’s same old static multiple dispatch.
Not sure what you mean. vtable's only allow for single dispatch in C++. For double dispatch you need the visitor pattern. For multiple dispatch, I don't know.
Closest to what Julia has in C++ is Bjarne's Open Multi-Methods article [1], but it was not implemented.
Another interesting quote from Bjarne's more recent How Can You Be So Certain article [2] is this:
> Unified function call: The notational distinction between x.f(y) and f(x,y) comes from the flawed OO notion that there always is a single most important object for an operation. I made a mistake adopting that. It was a shallow understanding at the time (but extremely fashionable). Even then, I pointed to sqrt(2)and x+y as examples of problems caused by that view.
This "mistake" is something Julia gets right.
[1] https://www.stroustrup.com/multimethods.pdf https://www.stroustrup.com/multimethods.pdf
[2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1962r0.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p196...
- mlthoughts2018 6y agoYou can use a tree for multiple dispatch (visitor pattern is not required, not sure why you mention that) or you can use a plain vtable approach where you take all the function operands and place them in a tuple. The type of that tuple (as a single object) then determines the multi-operand dispatch in the vtable approach. Some languages do make it harder to construct these tuple types, but in principle vrable is fine for multiple dispatch even in eg C++.
- stabbles 6y agoSure, you can implement it yourself. But even if you create an amazing tree/hashmap-based type-signature-tuple inheritance-aware multiple dispatch object, you still have to think about how to make other packages use it. I would also be interested how you would deal with the dynamic case of type erasure in this setup. Suppose I have a base class Base and derived classes A, B, and C. There's a set of functions f(A*, B*, A*) f(C*, A*, A*) for some combinations of pointers to A, B and C. Given a std::vector<std::tuple<Base*,Base*,Base*>> how do you apply the correct f to all its values?