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
7
votes
9 answers
What is - Single and Multiple Dispatch (in relation to .NET)?
Is it the same as overloading, if not, can you please provide and example of each in C#
I have read the responses to a similar question asked in SO ... i did not understand the responses posted to it.
Similar question asked here
EDIT: With the new…

Developer
- 17,809
- 26
- 66
- 92
7
votes
5 answers
Does Java support dispatching to specific implementations based on types of multiple objects like Lisp does?
Reading myself into Lisp, currently on this page (http://landoflisp.com), I found the following statement on the second last paragraph on the page that shows when clicking the link CLOS GUILD:
The important thing to note about the example is that…

Mathias Bader
- 3,585
- 7
- 39
- 61
7
votes
2 answers
Does new 'dynamic' variable type in .NET 4.0 solve the single/multiple method dispatch issue in CLR?
The problem of single dispatch is mostly familiar to people engaged in coding with statically typed languages like Java and C#. The basic idea is:
While the runtime polymorphism allows us to dispatch to the right method call according to the type…

Bubba88
- 1,910
- 20
- 44
7
votes
2 answers
Did the Loki multimethods make it into C++11?
I am reading Modern C++ Design Generic Programming and Design Patterns Applied by Andrei Alexandrescu and chapter 11 on multimethods deals exactly with the problem I am trying to solve. All source code from the book is published in a library named…

Martin Drozdik
- 12,742
- 22
- 81
- 146
6
votes
1 answer
Julia type conversion best practices
I have a function which requires a DateTime argument. A possibility is that a user might provide a ZonedDateTime argument. As far as I can tell there are three possible ways to catch this without breaking:
Accept both arguments in a single method,…

eagertom
- 81
- 5
6
votes
1 answer
Weird "Can't use unknown trait" when nextsame or callsame are used
Here's the program:
my %SUB-COUNTS;
say "Start";
multi sub trait_mod:(Sub $s where .name().contains("-logged"), :$AOP) {
$s.wrap({
say "Entering { $s.name }";
callsame;
});
}
multi sub trait_mod:(Sub $s where…

jjmerelo
- 22,578
- 8
- 40
- 86
6
votes
1 answer
Multiple dispatch for methods of a class in Julia
My question is how can I overload certain method within a certain class in Julia?
In other words suppose I have a following definition of a class:
type Sometype
prop::String
setValue::Function
# constructor
function Sometype()
…

aberdysh
- 1,634
- 2
- 13
- 34
6
votes
3 answers
c# multiple dispatch options?
I have these classes :
class Asset
{ }
class House:Asset
{ }
consider these outsiders static functions :
static void Foo (Asset a) { }
static void Foo (House h) { }
If i write :
House h = new House (...);
Foo(h);
it will call…

Royi Namir
- 144,742
- 138
- 468
- 792
5
votes
2 answers
(Nested?) Multiple Dispatch [Visitor Pattern]
I've come to a road block in my application architecture. I've just started using the visitor pattern to execute specific algos on abstract objects of which type I don't know at runtime. My problem is that my algo also depends on the type of a…

karczilla
- 105
- 2
- 12
5
votes
0 answers
How do I make multipledispatch accept objects of same class?
I am using multipledispatch to make a Point class, which has three constructors: one that takes a single integer, one that takes two, and one that takes an object of type Point. But I am unable to implement the third constructor as I don't know what…

Anchith Acharya
- 369
- 1
- 4
- 16
5
votes
1 answer
Is it possible to do multiple dispatch on NOT-a-type?
To simplify, I am trying to write a function with two arguments, where:
The base method accepts two Integers as arguments
func(x::Int, y::Int) = something
Additional methods accept either or both arguments as arbitrary types, map these arguments…

user3120868
- 93
- 5
5
votes
7 answers
Dynamic dispatch (runtime-polymorphism) with overloaded methods without using instanceof
I want to save Objects of Arc and Line in one ArrayList, then get the intersection of both. The question is how can I cast i and j to its original class. I know that instanceof works but that would be the dirtiest method.
public class…

McTi
- 91
- 5
5
votes
10 answers
Why doesn't C++ allow you to request a pointer to the most derived class?
(This question should probably be answered with a reference to Stroustrup.)
It seems extremely useful to be able to request a pointer to the most derived class, as in the following:
class Base { ... };
class DerivedA { ... };
class DerivedB { ...…

Matthew Lowe
- 1,350
- 1
- 17
- 29
5
votes
5 answers
Apples, oranges, and pointers to the most derived c++ class
Suppose I have a bunch of fruit:
class Fruit { ... };
class Apple : public Fruit { ... };
class Orange: public Fruit { ... };
And some polymorphic functions that operate on said fruit:
void Eat(Fruit* f, Pesticide* p) { ... }
void Eat(Apple* f,…

Matthew Lowe
- 1,350
- 1
- 17
- 29
5
votes
1 answer
How can I specify a type for a function argument without restricting its dimensions?
In Julia, I want to specify the type of a function argument as an array of arrays. So I have
function foo{T <: Any}(x::Array{Array{T}})
but if I set the argument x in the REPL, for example:
x = Array[[0,1],[1,2,3],[0,1,2,4]]
then it automatically…

StephUnna
- 153
- 6