A technique for polymorphic invocation of methods based on the types of many (or all) arguments. Compare to single-dispatch, used in common OO languages, where methods can only be polymorphic in the first argument -- the runtime resolution of a.doSomething(x, y, z) depends only on the type of a.
Questions tagged [multiple-dispatch]
106 questions
3
votes
1 answer
How do I check if a given `Method` object accepts a given `Tuple` of types in Julia 0.6?
The goal is to define a function that takes a method, and a tuple of types,
and returns true those types are a valid input for that method.
Not function, method
accepts(meth::Method, types::Tuple)::Bool
Here is a testset for this
using…

Frames Catherine White
- 27,368
- 21
- 87
- 137
3
votes
2 answers
Work around Java's static method dispatching without Double Dispatch/Visitor patterns
I am using a class Foo that provides these methods:
String overloadedMethod(Object)
String overloadedMethod(Goo)
Since Java statically dispatches on the non-receiver argument, I cannot just pass my value (which is an Object, but might have dynamic…

Yang Meyer
- 5,409
- 5
- 39
- 51
3
votes
3 answers
Multiple Dispatch: A conceptual necessity?
I wonder if the concept of multiple dispatch (that is, built-in support, as if the dynamic dispatch of virtual methods is extended to the method's arguments as well) should be included in an object-oriented language if its impact on performance…

domin
- 1,192
- 1
- 7
- 28
3
votes
1 answer
Overloading a function in two files (in Julia)
I'm gonna explain my problem on a minimal example. Let's say I have three files:
A.jl
module A
export Atype, f
type Atype
end
f = function(x::Atype)
println("f called with A")
end
end #module
B.jl
module B
export Btype, f
type Btype …

grześ
- 467
- 3
- 21
3
votes
1 answer
Julia: Understanding Multiple dispatch for OOP
Lets say I have the following types:
type cat
cry:: String
legs:: Int
fur:: String
end
type car
noise::String
wheels::Int
speed::Int
end
Lion = cat("meow", 4, "fuzzy")
vw = car("honk", 4, 45)
And I want to add a method describe to…

ccsv
- 8,188
- 12
- 53
- 97
3
votes
3 answers
Optimizing multiple dispatch notification algorithm in C#?
Sorry about the title, I couldn't think of a better way to describe the problem. Basically, I'm trying to implement a collision system in a game. I want to be able to register a "collision handler" that handles any collision of two objects (given in…

Robert Fraser
- 10,649
- 8
- 69
- 93
3
votes
3 answers
Multiple dispatch for collision detection in C++?
I have circles, boxes and lines. And now I want to implement collision detection between them. This means that I have to have a function for each combination of two kinds of shapes. Of course I can use the same for line vs circle and circle vs line,…

user3174082
- 47
- 1
2
votes
0 answers
Creating docs for dispatched functions using Sphinx
I am using the multipledispatch package in order to dispatch some functions. I created meaningful docstrings for every function. The code just runs fine.
# md.py
from multipledispatch import dispatch
@dispatch(int, int)
def calc(a: int, b: int)…

Andi
- 3,196
- 2
- 24
- 44
2
votes
1 answer
Julia Val{c}() seems slow compared to dictionnary lookup
I'm still learning Julia's multiple dispatch and value-as-type approach.
Instantiating Val{c}() seems about 50times slower than dictionary lookup.
After that, dispatch seems 6 times faster than dictionary lookup.
Are these durations expected? Is it…

Thomas Jalabert
- 1,344
- 9
- 19
2
votes
0 answers
Double dispatch in R: S4 vs vctrs library
If we want to implement a double dispatch method in R, we currently have two options to choose from:
S4 methods
vctrs library S3-based double dispatch
I especially mean arithmetic operators, such as + or *.
How do they compare in terms of…

KrzJoa
- 71
- 2
- 4
2
votes
1 answer
Is the visitor pattern a better option than controlled use of RTTI?
I often find myself trying to decouple objects using the boost/QT signals. The naive way to do this is for each concrete type I want to communicate, I create a new signal and slot signature and wire up all the dependent objects. This leads to the…

dHubley
- 25
- 4
2
votes
2 answers
What is the correct way to specify that a Julia function can only take Dicts/Arrays whose contents are of certain types?
Let's say I have a function that expects an dict as input. Within that, this function can only handle values of that dict that are in a certain Union of allowed types. For this argument, the input can be Number, String, or Bool:
allowed_types =…

fergu
- 329
- 1
- 5
- 12
2
votes
2 answers
Polymorphic binary function
I have three shape classes Circle, Square, ConvexPolygon, and I have the functions
bool ShapesIntersect(const Circle& s1, const Circle& s2);
bool ShapesIntersect(const Circle& s1, const Square& s2);
// ... and the other 7 combinations
I would like…

Andrea Allais
- 447
- 4
- 6
2
votes
1 answer
Multiple dispatches on an a single overloaded operator in S3 (in R)
I want to overload the '*' (multiplication operator) in R, when using an S3 class.
I see that * is already generic in the system, but I also want it "generic2", i.e. dispatching on the second argument.
The use case is as follows: Say my class is…

Alex Gian
- 482
- 4
- 10
2
votes
4 answers
C++ Multiple Dispatch
Given following problem:
class Instrument {
};
class Guitar : public Instrument {
public:
void doGuitar() const;
};
class Piano : public Instrument {
public:
void doPiano() const;
};
I got a list of pointers to…

Kapa11
- 311
- 2
- 18