# \#multidispatch

**URL:** https://discourse.julialang.org/tag/multidispatch/674.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Precompilation and tracking dependencies](https://discourse.julialang.org/t/precompilation-and-tracking-dependencies/134530)

<div class="topic-metadata">

**Author:** [@epilliat](https://discourse.julialang.org/u/epilliat)\
**Replies:** 1\
**Last updated:** [December 14, 2025, 1:03am UTC](https://discourse.julialang.org/t/precompilation-and-tracking-dependencies/134530 "2025-12-14T01:03:09Z")

</div>

I’m somehow bouncing back on this post about the time it takes for precompilation, and I agree with @mattsignorelli that it can scare new users about the practical performance of Julia. I’ve also been frustrated a lot be…

---

## [Could type ambiguity based on \`Union\` of concrete types be eliminated?](https://discourse.julialang.org/t/could-type-ambiguity-based-on-union-of-concrete-types-be-eliminated/126221)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 4\
**Last updated:** [March 4, 2025, 6:03pm UTC](https://discourse.julialang.org/t/could-type-ambiguity-based-on-union-of-concrete-types-be-eliminated/126221 "2025-03-04T18:03:47Z")

</div>

MWE: julia\> foo(::Union{Int, Float64}, ::AbstractArray, ::AbstractArray) = 1 foo (generic function with 1 method) julia\> foo(::Int, ::Any, ::Any) = 2 foo (generic function with 2 methods) julia\> foo(1, \[1\], \[1\]) ERROR…

---

## [Extending type functionality in Python and Julia](https://discourse.julialang.org/t/extending-type-functionality-in-python-and-julia/122222)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 7\
**Last updated:** [November 6, 2024, 7:35pm UTC](https://discourse.julialang.org/t/extending-type-functionality-in-python-and-julia/122222 "2024-11-06T19:35:18Z")

</div>

I have been using Julia for the last 9 years. As one of the few (if not the only one) users of Julia in the institute I work, I was asked to give a talk about it. One of the things I want to talk about is the ease with w…

---

## [Coding different iterations over a dataset](https://discourse.julialang.org/t/coding-different-iterations-over-a-dataset/119675)

<div class="topic-metadata">

**Author:** [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Replies:** 3\
**Last updated:** [September 22, 2024, 6:26am UTC](https://discourse.julialang.org/t/coding-different-iterations-over-a-dataset/119675 "2024-09-22T06:26:32Z")

</div>

I have some code currently implemented via multiple dispatch that looks vaguely like: function process\_data(data,n) for i in 1:n # apply operation to entire data set, data end end function process\_data(data\_se…

---

## [Understanding multiple dispatch](https://discourse.julialang.org/t/understanding-multiple-dispatch/76601)

<div class="topic-metadata">

**Author:** [@how](https://discourse.julialang.org/u/how)\
**Replies:** 30\
**Last updated:** [August 21, 2024, 9:00pm UTC](https://discourse.julialang.org/t/understanding-multiple-dispatch/76601 "2024-08-21T21:00:41Z")

</div>

Hi, I am studying Multiple dispatch, and have some troubles. While studying Julia language, I understood that Multiple dispatch is something that selecting which method to be applied based on the argument’s type. In t…

---

## [Naming macro and function the same](https://discourse.julialang.org/t/naming-macro-and-function-the-same/117959)

<div class="topic-metadata">

**Author:** [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Replies:** 7\
**Last updated:** [August 9, 2024, 5:26am UTC](https://discourse.julialang.org/t/naming-macro-and-function-the-same/117959 "2024-08-09T05:26:13Z")

</div>

In the Source code of Reexport, they define a macro Reexport, inmediately define a behaviour (I assume macros can also have multiple dispatch…?) and then they define a function with the same name: macro reexport(ex::Exp…

---

## [Claim (false): Julia isn't multiple dispatch but overloading](https://discourse.julialang.org/t/claim-false-julia-isnt-multiple-dispatch-but-overloading/42370)

<div class="topic-metadata">

**Author:** [@dataSurfer](https://discourse.julialang.org/u/dataSurfer)\
**Replies:** 133\
**Last updated:** [May 20, 2024, 1:27pm UTC](https://discourse.julialang.org/t/claim-false-julia-isnt-multiple-dispatch-but-overloading/42370 "2024-05-20T13:27:02Z")

</div>

I heard a rumour that Julia’s multiple dispatch is “fake news”, in reality it’s overloading because you compile the function before it is run and all you are doing in Julia is just a series of compile and run actions. Is…

---

## [Technical term for "operator inference" related to multiple dispatch](https://discourse.julialang.org/t/technical-term-for-operator-inference-related-to-multiple-dispatch/114109)

<div class="topic-metadata">

**Author:** [@younes](https://discourse.julialang.org/u/younes)\
**Replies:** 5\
**Last updated:** [May 10, 2024, 5:19pm UTC](https://discourse.julialang.org/t/technical-term-for-operator-inference-related-to-multiple-dispatch/114109 "2024-05-10T17:19:45Z")

</div>

I have defined the operator \< for my custom type Person: begin struct Person name::String age::Int end import Base: \< function \<(a::Person, b::Person)::Bool return a.age \< b.age end # Example …

---

## [Refactoring Julia Modules for Shape Representation and Canvas Drawing](https://discourse.julialang.org/t/refactoring-julia-modules-for-shape-representation-and-canvas-drawing/114095)

<div class="topic-metadata">

**Author:** [@Akhil\_Akkapelli](https://discourse.julialang.org/u/Akhil_Akkapelli)\
**Replies:** 1\
**Last updated:** [May 10, 2024, 11:21am UTC](https://discourse.julialang.org/t/refactoring-julia-modules-for-shape-representation-and-canvas-drawing/114095 "2024-05-10T11:21:53Z")

</div>

I have two Julia modules, “Shape.jl” and “Canvas.jl”, which define shapes and a canvas for drawing them. The code works as intended, but I’m wondering if there’s a cleaner and more efficient way to structure these module…

---

## [This function seems to allocate memory only if the argument types are not annotated in the definition](https://discourse.julialang.org/t/this-function-seems-to-allocate-memory-only-if-the-argument-types-are-not-annotated-in-the-definition/110193)

<div class="topic-metadata">

**Author:** [@Joaquin\_Rodriguez](https://discourse.julialang.org/u/Joaquin_Rodriguez)\
**Replies:** 5\
**Last updated:** [February 14, 2024, 1:41pm UTC](https://discourse.julialang.org/t/this-function-seems-to-allocate-memory-only-if-the-argument-types-are-not-annotated-in-the-definition/110193 "2024-02-14T13:41:17Z")

</div>

I am defining a custom data type that behaves like a vector (in the linear algebra sense). I defined it as a structure with a 6-element StaticVector that holds the underlying data: using StaticArrays struct MyVectorTyp…

---

## [Any way to multiple dispatch on functions?\`](https://discourse.julialang.org/t/any-way-to-multiple-dispatch-on-functions/107318)

<div class="topic-metadata">

**Author:** [@Jad\_Zeitouni](https://discourse.julialang.org/u/Jad_Zeitouni)\
**Replies:** 7\
**Last updated:** [December 8, 2023, 9:50am UTC](https://discourse.julialang.org/t/any-way-to-multiple-dispatch-on-functions/107318 "2023-12-08T09:50:01Z")

</div>

I defined two abstract types, call them MyType and MyFrozenType{T\<:MyType}. Subtypes SpecificFrozenType \<: MyFrozenStruct{SpecificType} are usually defined as SpecificFrozenType(x::SpecificType, v::Vector) Now, I have …

---

## [Define multiple methods or one method with union types?](https://discourse.julialang.org/t/define-multiple-methods-or-one-method-with-union-types/101674)

<div class="topic-metadata">

**Author:** [@kunzaatko](https://discourse.julialang.org/u/kunzaatko)\
**Replies:** 4\
**Last updated:** [July 17, 2023, 2:03pm UTC](https://discourse.julialang.org/t/define-multiple-methods-or-one-method-with-union-types/101674 "2023-07-17T14:03:17Z")

</div>

What is the preferred way to implement methods that allow multiple types? Option A: function method(a::Union{Tuple{Integer,Integer}, Integer}, b::Union{Tuple{Integer,Integer}, Integer}) a = a isa Integer ? (a,a) : …

---

## [Add method with different arguments to existing function?](https://discourse.julialang.org/t/add-method-with-different-arguments-to-existing-function/96190)

<div class="topic-metadata">

**Author:** [@abehersan](https://discourse.julialang.org/u/abehersan)\
**Replies:** 6\
**Last updated:** [March 31, 2023, 7:45am UTC](https://discourse.julialang.org/t/add-method-with-different-arguments-to-existing-function/96190 "2023-03-31T07:45:23Z")

</div>

Hi! Suppose I have a function f(a::Number, b::Number; c=1, d=2.0, e="hello") and I want to add a method to it with different kwargs, but with the same positional arguments, say for example f(a::Number, b::Number; f="bye…

---

## [Best way to select implementation based on runtime argument? (dispatch vs. control flow)](https://discourse.julialang.org/t/best-way-to-select-implementation-based-on-runtime-argument-dispatch-vs-control-flow/95479)

<div class="topic-metadata">

**Author:** [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)\
**Replies:** 10\
**Last updated:** [March 6, 2023, 7:40pm UTC](https://discourse.julialang.org/t/best-way-to-select-implementation-based-on-runtime-argument-dispatch-vs-control-flow/95479 "2023-03-06T19:40:31Z")

</div>

I’ve been running into the following question: What is the most “sensible” or idiomatic way to select a function implementation based on a runtime argument (by which I mean, it could potentially be passed e. g. as a comm…

---

## [Type Inference](https://discourse.julialang.org/t/type-inference/89761)

<div class="topic-metadata">

**Author:** [@tchebycheff](https://discourse.julialang.org/u/tchebycheff)\
**Replies:** 6\
**Last updated:** [November 25, 2022, 8:23am UTC](https://discourse.julialang.org/t/type-inference/89761 "2022-11-25T08:23:12Z")

</div>

I always held automatic type inference as one of Julia’s distinguishing features. Why are packages full of type qualifications? Is it the performance improvement, error handling or just the coolness factor? P.S. I hope…

---

## [Parameterize all types excluding a certain type](https://discourse.julialang.org/t/parameterize-all-types-excluding-a-certain-type/89639)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 6\
**Last updated:** [November 2, 2022, 6:32pm UTC](https://discourse.julialang.org/t/parameterize-all-types-excluding-a-certain-type/89639 "2022-11-02T18:32:22Z")

</div>

Suppose I have a parameterized type Foo{T} with a field val::T, and an abstract type Bar. I would like to: # Library Code struct Foo{T} val::T end abstract type Bar end baz(bar::Bar, a::Foo, b::Foo) = baz(bar, a.v…

---

## [Find where a specific method gets called](https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 2\
**Last updated:** [October 21, 2022, 3:09pm UTC](https://discourse.julialang.org/t/find-where-a-specific-method-gets-called/89068 "2022-10-21T15:09:07Z")

</div>

Is there a way to find all places in my code base where a specific method (not function!) gets called (or may get called)? The method in question for me is Base.\*, so greping for \* over the whole code base produces way t…

---

## [Methods imported from submodules are overwritten, not extended](https://discourse.julialang.org/t/methods-imported-from-submodules-are-overwritten-not-extended/87995)

<div class="topic-metadata">

**Author:** [@tom-plaa](https://discourse.julialang.org/u/tom-plaa)\
**Replies:** 3\
**Last updated:** [September 30, 2022, 2:00pm UTC](https://discourse.julialang.org/t/methods-imported-from-submodules-are-overwritten-not-extended/87995 "2022-09-30T14:00:06Z")

</div>

I assumed that by defining different argument requirements I would get different methods for an already imported function from a submodule, but it seems I am getting an overwrite instead of an extension. What’s the idiom…

---

## [Using Multiple Dispatch with Keyword Arguments](https://discourse.julialang.org/t/using-multiple-dispatch-with-keyword-arguments/87343)

<div class="topic-metadata">

**Author:** [@Snowy](https://discourse.julialang.org/u/Snowy)\
**Replies:** 4\
**Last updated:** [September 16, 2022, 5:36am UTC](https://discourse.julialang.org/t/using-multiple-dispatch-with-keyword-arguments/87343 "2022-09-16T05:36:32Z")

</div>

Hi all, Still a new Julia user here, but hoping to find some help. I’m building an application that will take in user-provided information and process it. There are a few required arguments from the user, and some optio…

---

## [Article about Multiple Dispatch](https://discourse.julialang.org/t/article-about-multiple-dispatch/76855)

<div class="topic-metadata">

**Author:** [@djpasseyjr](https://discourse.julialang.org/u/djpasseyjr)\
**Replies:** 7\
**Last updated:** [August 12, 2022, 9:19pm UTC](https://discourse.julialang.org/t/article-about-multiple-dispatch/76855 "2022-08-12T21:19:16Z")

</div>

Wow, I’d really like to improve the article. I hope that the article is a useful Julia tutorial, and I’d like to preserve the good aspects of it but it sounds like I was doing some damage. I made some small changes to …

---

## [Can DataFrames be distinguished by type?](https://discourse.julialang.org/t/can-dataframes-be-distinguished-by-type/85442)

<div class="topic-metadata">

**Author:** [@Soldalma](https://discourse.julialang.org/u/Soldalma)\
**Replies:** 1\
**Last updated:** [August 7, 2022, 11:31pm UTC](https://discourse.julialang.org/t/can-dataframes-be-distinguished-by-type/85442 "2022-08-07T23:31:46Z")

</div>

I would like to have a function call fail or not depending on the type of a DataFrame. I cannot distinguish the DataFrames by column types or size. For example, I would have two identical functions except for the argume…

---

## [\[ANN\] Virtual.jl: optimizing dynamic calls away through "virtual" multiple dispatch](https://discourse.julialang.org/t/ann-virtual-jl-optimizing-dynamic-calls-away-through-virtual-multiple-dispatch/84413)

<div class="topic-metadata">

**Author:** [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Replies:** 14\
**Last updated:** [July 19, 2022, 10:43pm UTC](https://discourse.julialang.org/t/ann-virtual-jl-optimizing-dynamic-calls-away-through-virtual-multiple-dispatch/84413 "2022-07-19T22:43:56Z")

</div>

P.S: Recently I’m planning to implement a zero-latency scripting language in Julia, hence I need this feature. The package can be regarded as a generalization to ValSplit.jl, supporting fast runtime polymorphisms for mul…

---

## [If mutiple dispatch is done at compile time, wouldn't that make things faster?](https://discourse.julialang.org/t/if-mutiple-dispatch-is-done-at-compile-time-wouldnt-that-make-things-faster/81496)

<div class="topic-metadata">

**Author:** [@thisismygitrepo](https://discourse.julialang.org/u/thisismygitrepo)\
**Replies:** 3\
**Last updated:** [May 23, 2022, 1:44pm UTC](https://discourse.julialang.org/t/if-mutiple-dispatch-is-done-at-compile-time-wouldnt-that-make-things-faster/81496 "2022-05-23T13:44:11Z")

</div>

I’m not an expert in any sense, but can we not get MOAR speed if we don’t have to check types at runtime? So, if my code is statically styled, would that make it faster?

---

## [Dispatch on lambda functions](https://discourse.julialang.org/t/dispatch-on-lambda-functions/80064)

<div class="topic-metadata">

**Author:** [@jj-404](https://discourse.julialang.org/u/jj-404)\
**Replies:** 5\
**Last updated:** [April 26, 2022, 2:22pm UTC](https://discourse.julialang.org/t/dispatch-on-lambda-functions/80064 "2022-04-26T14:22:05Z")

</div>

Hi, is there a way to dispatch on lambda functions? It seems that lambda’s don’t have a specific type for themselves (unlike Functions), but are rather uniquely typed with a counter (var"#29#30"). I would like to dispatc…

---

## [When not to use Multiple Dispatch?](https://discourse.julialang.org/t/when-not-to-use-multiple-dispatch/78792)

<div class="topic-metadata">

**Author:** [@helgee](https://discourse.julialang.org/u/helgee)\
**Replies:** 6\
**Last updated:** [March 31, 2022, 1:40pm UTC](https://discourse.julialang.org/t/when-not-to-use-multiple-dispatch/78792 "2022-03-31T13:40:55Z")

</div>

Hi folks! On my endless quest to make AstroTime.jl the best date and time handling package in the universe, I am pondering another redesign :see\_no\_evil: When modelling my problem domains, I always gravitate to pushing…

---

## [Dispatch on enum](https://discourse.julialang.org/t/dispatch-on-enum/77398)

<div class="topic-metadata">

**Author:** [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Replies:** 7\
**Last updated:** [March 4, 2022, 5:17pm UTC](https://discourse.julialang.org/t/dispatch-on-enum/77398 "2022-03-04T17:17:40Z")

</div>

Hey all :slight\_smile: Is it possible to dispatch a function on different enum instances. Something like this: julia\> @enum E a b julia\> f(::Type{a}) = :a julia\> f(::Type{b}) = :b julia\> f(a) :a

---

## [Best practice to support multiple implementations](https://discourse.julialang.org/t/best-practice-to-support-multiple-implementations/74240)

<div class="topic-metadata">

**Author:** [@roh\_codeur](https://discourse.julialang.org/u/roh_codeur)\
**Replies:** 16\
**Last updated:** [January 14, 2022, 1:34pm UTC](https://discourse.julialang.org/t/best-practice-to-support-multiple-implementations/74240 "2022-01-14T13:34:57Z")

</div>

Hi I am a newbie to the language, coming from an OOP background. I have a method as below: function run(downloader) downloader.download() end the downloader can have several implementations, for instance, could…

---

## [Set default tolerance for isapprox()](https://discourse.julialang.org/t/set-default-tolerance-for-isapprox/74337)

<div class="topic-metadata">

**Author:** [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Replies:** 6\
**Last updated:** [January 10, 2022, 2:37pm UTC](https://discourse.julialang.org/t/set-default-tolerance-for-isapprox/74337 "2022-01-10T14:37:16Z")

</div>

How can I define isapprox() for a type such that I can set a default tolerance but the user can override it if required? struct MyType v::Float64 end Base.isapprox(x::MyType, y::MyType) = isapprox(x.v, y.v, atol=10e-…

---

## [New dispatch for isless() does not work](https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025)

<div class="topic-metadata">

**Author:** [@jafar.isbarov](https://discourse.julialang.org/u/jafar.isbarov)\
**Replies:** 2\
**Last updated:** [January 4, 2022, 11:23am UTC](https://discourse.julialang.org/t/new-dispatch-for-isless-does-not-work/74025 "2022-01-04T11:23:31Z")

</div>

I need to be able to compare instances of a struct named Hijri, so I have defined a new method for the isless() function as follows: function isless(a::Hijri, b::Hijri) tuple\_a = datetuple(a) tuple\_b = datetuple(b) …

---

## [Performance benefits of multiple dispatch](https://discourse.julialang.org/t/performance-benefits-of-multiple-dispatch/73254)

<div class="topic-metadata">

**Author:** [@Niall](https://discourse.julialang.org/u/Niall)\
**Replies:** 20\
**Last updated:** [December 19, 2021, 1:03pm UTC](https://discourse.julialang.org/t/performance-benefits-of-multiple-dispatch/73254 "2021-12-19T13:03:14Z")

</div>

OK, so I thought it’d be a great idea to demonstrate to students on their very first lesson the performance benefits of Julia’s Top Notion: multiple dispatch. So I wrote the program shown below. Only problem is, the resu…

[Next page](https://discourse.julialang.org/tag/multidispatch/674.md?match_all_tags=true&page=1&tags%5B%5D=multidispatch)
