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
1
vote
1 answer
Detect which function to call based on argument type in OpenWatcom C language
I have 2 implementations of the same function based on the pointer size in the argument:
/* Writes a $-delimited string to stdout. */
static inline void _printmsgx(const char *msg);
#pragma aux _printmsgx = "mov ah, 9" "int 0x21" parm [ dx ]…

pts
- 80,836
- 20
- 110
- 183
1
vote
1 answer
How can I pass keyword arguments to the `range` function from within another function and maintain user flexibility with Julia?
I am writing my first module in Julia. I have a function f which will use a vector or range for some calculations. I would like to create a method of this function which will create a range using the range function before proceeding with the…

Nathan Boyer
- 1,412
- 1
- 6
- 20
1
vote
3 answers
Invoking a method overloaded where all arguments implement the same interface
My starting point is the following:
- I have a method, transform, which I overloaded to behave differently depending on the type of arguments that are passed in (see transform(A a1, A a2) and transform(A a1, B b) in my example below)
- All these…

double07
- 2,565
- 2
- 22
- 22
1
vote
1 answer
Define two traits such that a function must exist for the cartesian product of the two sets of types that implement it
I would like to create two traits, SaveSource and SaveDestination, such that when some types implement these traits, the function:
fn save(a, b)
must be implemented for all a : SaveSource and b : SaveDestination (and when a new type is added to…

user8099375
- 11
- 1
1
vote
1 answer
Does java support multiple dispatch? If not how is the below code working?
Does java support multiple dispatch? If not how is the below code working?
Account.java
public interface Account
{
public void calculateInterest();
}
SavingsAccount.java
public class SavingsAccount implements…

Java Beginner
- 1,635
- 11
- 29
- 51
1
vote
1 answer
Multiple dispatch and multi-methods
What are they, what's the different between them?
Many sources, like Wikipedia, claim they're the same thing, but others explicitly say the opposite, like sbi in this question:
First: "Visitor Pattern is a way to simulate Double Dispatching in…

peoro
- 25,562
- 20
- 98
- 150
1
vote
5 answers
Are functions mutable in multiple dispatch systems?
Have I understood correctly that in (most? some?) multiple dispatch languages each method gets added to the function at some point in time of program's execution.
Can I then conclude that multiple dispatch as a feature forces functions to be…

Aivar
- 6,814
- 5
- 46
- 78
1
vote
1 answer
Scala dynamic dispatch with parameterized function
How is it possible to make this code work?
As far as I know, Scala doesn't have dynamic dispatch (similar to Java). Is it possible to simulate dynamic dispatching somehow?
Or what's the best solution?
object Tezt {
case class SuperClazz()
…

pedrorijo91
- 7,635
- 9
- 44
- 82
1
vote
1 answer
How encode in a dictionary multiple functions of different types
I'm building a interpreter in F#. I'm trying to be clever and generalize the interpretation of primitive operators as function calls (in this case, as reductions).
This is the idea:
let reduce fx values =
Array.reduce values fx
let…

mamcx
- 15,916
- 26
- 101
- 189
1
vote
3 answers
Virtual functions with two operands that can take many different types
Let me start with a concrete example. In C++, I have a hierarchy of classes under the abstract base class CollisionVolume. Any collision volume needs to be able to detectCollision with any other volume. This collision code is specialized based on…

Philippe Beaudoin
- 3,290
- 1
- 22
- 25
1
vote
4 answers
Overloading method in derived class vs multiple dispatch
According to Wikipedia, Multiple Dispatch is when
... a function or method can be dynamically dispatched based on the run time (dynamic) type of more than one of its arguments.
However, in C++ I can override a function in the derived…

Mike Vella
- 10,187
- 14
- 59
- 86
1
vote
4 answers
Defining "overloaded" functions in python
I really like the syntax of the "magic methods" or whatever they are called in Python, like
class foo:
def __add__(self,other): #It can be called like c = a + b
pass
The call
c = a + b
is then translated to
a.__add__(b)
Is it…

Ivan Oseledets
- 2,270
- 4
- 23
- 28
0
votes
1 answer
How to efficiently and generally implement multiple dispatch?
Multiple dispatch is a useful generalization of traditional single dispatch that is found in any OOP language. However, it's not nearly so clear how it can be implemented in an efficient and simple way. Single dispatch is easy: any old website or…

v-rob
- 123
- 1
- 4
0
votes
1 answer
Multiple dispatch - "function requires at least 1 positional argument"
In a multiple dispatch situation I don't understand why I constantly run into an error saying: TypeError: some_func requires at least 1 positional argument.
For example, we have a following function:
from functools import…

NotAName
- 3,821
- 2
- 29
- 44
0
votes
1 answer
using multiple-dispatch for functions when they are defined in different modules (Julia)
I tried to use multiple-dispatch for functions that are defined in different modules in Julia, e.g.:
module A
export f
f(i::Integer) = println(i)
end
module B
export f
f(i::AbstractFloat) = println(i)
end
using .A, .B
f(.1)
But it returns an…

PokeLu
- 767
- 8
- 17