3 ms·
I wasn't aware that you could do double dispatch without encoding it yourself with something like the visitor pattern, is that what you meant?
by sixbrx 13y ago
I wasn't aware that you could do double dispatch without encoding it yourself with something like the visitor pattern, is that what you meant?
- UK-AL 13y agoIs this what your looking for http://blogs.msdn.com/b/shawnhar/archive/2011/04/05/visitor-and-multiple-dispatch-via-c-dynamic.aspx?Redirected=true http://blogs.msdn.com/b/shawnhar/archive/2011/04/05/visitor-... Double dispatch without visitor pattern, using dynamic type.
- sixbrx 13y agoThat's a neat feature! So my aside about single dispatch was misplaced. What I'm really after though is somewhat the opposite, which is static dispatch so that the functions called are known at compile time and can be optimized that way (I do a lot of numerics coding), so avoiding any method resolution lookup and even the vtable jumps and resulting target mispredicts. That's a nice feature of both type classes and ML's module system as usually implemented in functional languages. One really nice thing is they can also typically "dispatch" statically on return types of functions too which makes for some neat patterns as well using type inference. Anyway thanks for pointing to that. It definitely beats the visitor pattern as is necessary in Java. And I assume it would work for more than two parameters too, which is another advantage over standard visitor.