# \#dispatch

**URL:** https://discourse.julialang.org/tag/dispatch/313.md

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

---

## [\[ANN\] InstanceDispatch.jl: Dispatch-on-value with anyting that defines a \`Base.instances\` method](https://discourse.julialang.org/t/ann-instancedispatch-jl-dispatch-on-value-with-anyting-that-defines-a-base-instances-method/130838)

<div class="topic-metadata">

**Author:** [@klafyvel](https://discourse.julialang.org/u/klafyvel)\
**Replies:** 8\
**Last updated:** [August 24, 2026, 12:56pm UTC](https://discourse.julialang.org/t/ann-instancedispatch-jl-dispatch-on-value-with-anyting-that-defines-a-base-instances-method/130838 "2026-08-24T12:56:28Z")

</div>

Hi there, I just started the registration process for InstanceDispatch.jl, a single-macro package that writes for you a method that dispatches on methods with value-type from a type that defines a Base.instances method …

---

## [Invoke for functor methods](https://discourse.julialang.org/t/invoke-for-functor-methods/135397)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 1\
**Last updated:** [February 2, 2026, 8:20am UTC](https://discourse.julialang.org/t/invoke-for-functor-methods/135397 "2026-02-02T08:20:36Z")

</div>

A minimal example demonstrating the use of invoke() might look something like the following. julia\> abstract type A end struct B \<: A end f(a::A) = "hello world from $a" f(b::B) = invoke(f, Tuple{A}…

---

## [Idiomatic evaluate for scalar, allocate and broadcast for array?](https://discourse.julialang.org/t/idiomatic-evaluate-for-scalar-allocate-and-broadcast-for-array/135147)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 7\
**Last updated:** [January 21, 2026, 7:01am UTC](https://discourse.julialang.org/t/idiomatic-evaluate-for-scalar-allocate-and-broadcast-for-array/135147 "2026-01-21T07:01:58Z")

</div>

In several cases I’ve come across the following pattern: function f(x; kwargs...) #intense pre-computation that depend on kwargs but not x result = 0.0 \* x; # one way to preallocate for e.g. x::Vector, but not for scala…

---

## [Why can't a tuple of types have an abstract type with Type selectors?](https://discourse.julialang.org/t/why-cant-a-tuple-of-types-have-an-abstract-type-with-type-selectors/134036)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 7\
**Last updated:** [November 23, 2025, 11:12am UTC](https://discourse.julialang.org/t/why-cant-a-tuple-of-types-have-an-abstract-type-with-type-selectors/134036 "2025-11-23T11:12:10Z")

</div>

julia\> 1 isa Int true julia\> (1,) isa Tuple{Int} true julia\> Int isa Type{Int} true julia\> (Int,) isa Tuple{Type{Int}} # ??? false And how does dispatch work if this doesn’t work for method signatures as tuple types? …

---

## [Value Dispatch Macro](https://discourse.julialang.org/t/value-dispatch-macro/133435)

<div class="topic-metadata">

**Author:** [@csvance](https://discourse.julialang.org/u/csvance)\
**Replies:** 4\
**Last updated:** [October 26, 2025, 8:57pm UTC](https://discourse.julialang.org/t/value-dispatch-macro/133435 "2025-10-26T20:57:07Z")

</div>

I’ve been messing around with the idea of streamlining dynamic dispatch on values for non hot path / glue code. The pattern is for multiple dispatch to dispatch to a function I define with a macro based on the known type…

---

## [Dynamic Type in CxxWrap.jl](https://discourse.julialang.org/t/dynamic-type-in-cxxwrap-jl/133007)

<div class="topic-metadata">

**Author:** [@phK3](https://discourse.julialang.org/u/phK3)\
**Replies:** 1\
**Last updated:** [October 20, 2025, 9:56am UTC](https://discourse.julialang.org/t/dynamic-type-in-cxxwrap-jl/133007 "2025-10-20T09:56:31Z")

</div>

I want to use CxxWrap.jl to create a Julia wrapper for a C++ library. On the Julia side, I want to dispatch on the type of my arguments. But when using CxxWrap, the Julia side only seems to know about the static return…

---

## [A question on dispatch on type parameter being UnionAll](https://discourse.julialang.org/t/a-question-on-dispatch-on-type-parameter-being-unionall/132070)

<div class="topic-metadata">

**Author:** [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Replies:** 3\
**Last updated:** [September 3, 2025, 1:26pm UTC](https://discourse.julialang.org/t/a-question-on-dispatch-on-type-parameter-being-unionall/132070 "2025-09-03T13:26:52Z")

</div>

I’m a bit curious about the following problem, it’s not a big deal and has an easy solution, but anyway struct A{T,S} t::T s::S end struct B{V\<:A} v::Vector{V} end b1 = B(\[A(1,2), A(3,4.0)\]) # element typ…

---

## [Multidispatch based on value of positional argument](https://discourse.julialang.org/t/multidispatch-based-on-value-of-positional-argument/131584)

<div class="topic-metadata">

**Author:** [@Snowy](https://discourse.julialang.org/u/Snowy)\
**Replies:** 4\
**Last updated:** [August 13, 2025, 4:35pm UTC](https://discourse.julialang.org/t/multidispatch-based-on-value-of-positional-argument/131584 "2025-08-13T16:35:55Z")

</div>

Hi, Just to make sure I understand multidispatch correctly here: There is no way to multidispatch based on a value in a positional argument, correct? For example, something like: function multidispatch(x,y,string\_argu…

---

## [\[ANN\] MultipleInterfaces.jl: Interfaces with multiple inheritance and multiple dispatch](https://discourse.julialang.org/t/ann-multipleinterfaces-jl-interfaces-with-multiple-inheritance-and-multiple-dispatch/130796)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 28\
**Last updated:** [August 8, 2025, 12:39am UTC](https://discourse.julialang.org/t/ann-multipleinterfaces-jl-interfaces-with-multiple-inheritance-and-multiple-dispatch/130796 "2025-08-08T00:39:15Z")

</div>

I’m pleased to announce the release of MultipleInterfaces.jl. MultipleInterfaces.jl provides a powerful way to define and work with interfaces in Julia. With MultipleInterfaces.jl you can declare an interface that is def…

---

## [How far does type instability propagate?](https://discourse.julialang.org/t/how-far-does-type-instability-propagate/130350)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 10\
**Last updated:** [July 4, 2025, 8:37am UTC](https://discourse.julialang.org/t/how-far-does-type-instability-propagate/130350 "2025-07-04T08:37:38Z")

</div>

I have a function type\_uint(val::Integer) ::Type{\<:Unsigned} which returns the smallest UInt type that can still represent val without overflowing. I use this everywhere in my code, but only at top level. For example, g…

---

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

<div class="topic-metadata">

**Author:** [@Cyan](https://discourse.julialang.org/u/Cyan)\
**Replies:** 6\
**Last updated:** [June 14, 2025, 8:34am UTC](https://discourse.julialang.org/t/dispatch-on-keywords/129854 "2025-06-14T08:34:01Z")

</div>

I wrote these two functions function test(;e::Float64) return e^2 end function test(;e::Int) return e\*2 end I obtain the right answer when test(1.) or test(1), but the test(e=1.) returns an error of: TypeErro…

---

## [Using invoke() to call more general method](https://discourse.julialang.org/t/using-invoke-to-call-more-general-method/125324)

<div class="topic-metadata">

**Author:** [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)\
**Replies:** 4\
**Last updated:** [January 29, 2025, 6:05pm UTC](https://discourse.julialang.org/t/using-invoke-to-call-more-general-method/125324 "2025-01-29T18:05:18Z")

</div>

I have a method for convert() that I use on various subtypes of a ConfigStruct type, to initialize from a dictionary. For a couple of subtypes, I want to define specific behaviors (e.g., catch deprecated keys and map th…

---

## [Dispatch and junk values](https://discourse.julialang.org/t/dispatch-and-junk-values/124497)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 10\
**Last updated:** [January 7, 2025, 2:57pm UTC](https://discourse.julialang.org/t/dispatch-and-junk-values/124497 "2025-01-07T14:57:14Z")

</div>

I have the following situation, where I have a function, where depending on the types of the supplied objects, I may or may not use all arguments. I then wish to define a shortcut function for some types of the supplied …

---

## [RCall: function / method conflict with R functions](https://discourse.julialang.org/t/rcall-function-method-conflict-with-r-functions/124370)

<div class="topic-metadata">

**Author:** [@hatmatrix](https://discourse.julialang.org/u/hatmatrix)\
**Replies:** 11\
**Last updated:** [January 6, 2025, 4:17pm UTC](https://discourse.julialang.org/t/rcall-function-method-conflict-with-r-functions/124370 "2025-01-06T16:17:18Z")

</div>

Hello everyone, I am trying to figure out the resolution order of conflicting methods, particularly as it regards to the theme function in ggplot2 from R and Plots in Julia. Following up on the question here: I’ve tr…

---

## [Pluto.jl - How do I dispatch to a subtype created in a notebook?](https://discourse.julialang.org/t/pluto-jl-how-do-i-dispatch-to-a-subtype-created-in-a-notebook/124162)

<div class="topic-metadata">

**Author:** [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Replies:** 2\
**Last updated:** [December 25, 2024, 1:18am UTC](https://discourse.julialang.org/t/pluto-jl-how-do-i-dispatch-to-a-subtype-created-in-a-notebook/124162 "2024-12-25T01:18:30Z")

</div>

I created a small package called ProblematicAnimals.jl to demonstrate a problem I’m having with Pluto.jl notebooks. I sincerely hope a solution to this can be found. Defined outside of Pluto abstract type AbstractAnima…

---

## [Nothing and type stability in kwargs](https://discourse.julialang.org/t/nothing-and-type-stability-in-kwargs/123532)

<div class="topic-metadata">

**Author:** [@kockahonza](https://discourse.julialang.org/u/kockahonza)\
**Replies:** 6\
**Last updated:** [December 11, 2024, 10:50am UTC](https://discourse.julialang.org/t/nothing-and-type-stability-in-kwargs/123532 "2024-12-11T10:50:29Z")

</div>

Hi, so this is a fairly general question, but is it possible to use Nothing without type stability related performance hits? A specific example I have now is a simple simulator where I want to implement multiple optional…

---

## [Function specialization based on values, not just types](https://discourse.julialang.org/t/function-specialization-based-on-values-not-just-types/123043)

<div class="topic-metadata">

**Author:** [@benc](https://discourse.julialang.org/u/benc)\
**Replies:** 18\
**Last updated:** [November 26, 2024, 12:42pm UTC](https://discourse.julialang.org/t/function-specialization-based-on-values-not-just-types/123043 "2024-11-26T12:42:38Z")

</div>

I’m working on Markov Chains where a lot of recursive functions have a mathematical parametric equation with a base case, simplified to function f(xs, 1) @info "Base case" end function f(xs, val) @info "Gene…

---

## [Macro usage: create dispatch for vector length](https://discourse.julialang.org/t/macro-usage-create-dispatch-for-vector-length/118142)

<div class="topic-metadata">

**Author:** [@heronrick](https://discourse.julialang.org/u/heronrick)\
**Replies:** 8\
**Last updated:** [September 26, 2024, 3:44pm UTC](https://discourse.julialang.org/t/macro-usage-create-dispatch-for-vector-length/118142 "2024-09-26T15:44:56Z")

</div>

Hello, I have an Idea I would like to implement for a module I am working on. I will try to explain, but I am not sure if such implementation would make much sense, probably there are better solutions. I have a macro, …

---

## [Understanding error "function type in method definition is not a type" for function-like types](https://discourse.julialang.org/t/understanding-error-function-type-in-method-definition-is-not-a-type-for-function-like-types/116105)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 9\
**Last updated:** [July 23, 2024, 5:16pm UTC](https://discourse.julialang.org/t/understanding-error-function-type-in-method-definition-is-not-a-type-for-function-like-types/116105 "2024-07-23T17:16:15Z")

</div>

I don’t understand why the second way to construct a method (dispatched by ::Val{2}) is not allowed: julia\> abstract type MyFunc \<: Function end julia\> struct MyF1 \<: MyFunc end julia\> (f::MyFunc)(::Val{1}) = "method …

---

## [Improper function nesting causes boxing/runtime dispatch?](https://discourse.julialang.org/t/improper-function-nesting-causes-boxing-runtime-dispatch/114307)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 3\
**Last updated:** [May 17, 2024, 7:00am UTC](https://discourse.julialang.org/t/improper-function-nesting-causes-boxing-runtime-dispatch/114307 "2024-05-17T07:00:01Z")

</div>

Note the code example below: struct Radix{N} Radix(n::Integer) = new{n}(); end # Nesting: testfunc! -\> \_add, \_addpositions function testfunc!(array, num, radix) \_add(a, b, ::Radix{2}) = a ⊻ b \_add(a, …

---

## [Why traits?](https://discourse.julialang.org/t/why-traits/105591)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 5\
**Last updated:** [November 19, 2023, 12:30pm UTC](https://discourse.julialang.org/t/why-traits/105591 "2023-11-19T12:30:20Z")

</div>

I’ve been trying to teach my students traits, only to realize that there is something I don’t fully understand. Is there any different between these two approaches to dispatch? struct A end struct B end ## Holy trait …

---

## [RFC: add a Type called AnyType that's subtyped by all other types except Any](https://discourse.julialang.org/t/rfc-add-a-type-called-anytype-thats-subtyped-by-all-other-types-except-any/93956)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 20\
**Last updated:** [October 26, 2023, 11:38pm UTC](https://discourse.julialang.org/t/rfc-add-a-type-called-anytype-thats-subtyped-by-all-other-types-except-any/93956 "2023-10-26T23:38:58Z")

</div>

Add AnyType between Any and all other types Situation The discussions here on Discourse and on Github make it clear that there are disagreements and confusion within the Julia community (including both users and core mem…

---

## [How to call the original Base.show function extended in DataFrames.jl while overriding it?](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437)

<div class="topic-metadata">

**Author:** [@raythurnevoid](https://discourse.julialang.org/u/raythurnevoid)\
**Replies:** 3\
**Last updated:** [October 1, 2023, 3:52am UTC](https://discourse.julialang.org/t/how-to-call-the-original-base-show-function-extended-in-dataframes-jl-while-overriding-it/104437 "2023-10-01T03:52:55Z")

</div>

I’m using the DataFrames.jl package and I want to change the default behavior of show(), I want to print all the rows and columns without passing additional arguments because I want it to work seamlessly while calling di…

---

## [Dispatch on physical quantity or creating distinct types that behave like a float](https://discourse.julialang.org/t/dispatch-on-physical-quantity-or-creating-distinct-types-that-behave-like-a-float/104098)

<div class="topic-metadata">

**Author:** [@cpf-work](https://discourse.julialang.org/u/cpf-work)\
**Replies:** 7\
**Last updated:** [September 25, 2023, 9:19am UTC](https://discourse.julialang.org/t/dispatch-on-physical-quantity-or-creating-distinct-types-that-behave-like-a-float/104098 "2023-09-25T09:19:16Z")

</div>

Let’s say I want to calculate the velocity of a free falling body in vacuum. I want to do this in dependence of gravitational constant and time or distance and time with a fixed gravitational constant. That would be eit…

---

## [Enable all functions to work on element of new type](https://discourse.julialang.org/t/enable-all-functions-to-work-on-element-of-new-type/103210)

<div class="topic-metadata">

**Author:** [@s-baumann](https://discourse.julialang.org/u/s-baumann)\
**Replies:** 2\
**Last updated:** [August 25, 2023, 11:09pm UTC](https://discourse.julialang.org/t/enable-all-functions-to-work-on-element-of-new-type/103210 "2023-08-25T23:09:54Z")

</div>

If I make a new struct that contains a certain type (a DataFrame in below example) like: struct StructContainingDataFrame df::DataFrame something\_else::Any end Is it then possible to make this work with all fun…

---

## [InlineDispatch.jl – A simple module to perform dispatch on the value of an expression](https://discourse.julialang.org/t/inlinedispatch-jl-a-simple-module-to-perform-dispatch-on-the-value-of-an-expression/102780)

<div class="topic-metadata">

**Author:** [@HanD](https://discourse.julialang.org/u/HanD)\
**Replies:** 0\
**Last updated:** [August 14, 2023, 6:41am UTC](https://discourse.julialang.org/t/inlinedispatch-jl-a-simple-module-to-perform-dispatch-on-the-value-of-an-expression/102780 "2023-08-14T06:41:08Z")

</div>

Based on a discussion here on Discourse, I’m happy to announce a new package called InlineDispatch.jl for dispatching on values using anonymous functions. The following expression: @dispatch expr begin v::T…

---

## [Test for a zero-valued Tuple in where statement](https://discourse.julialang.org/t/test-for-a-zero-valued-tuple-in-where-statement/97579)

<div class="topic-metadata">

**Author:** [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)\
**Replies:** 15\
**Last updated:** [April 17, 2023, 9:52pm UTC](https://discourse.julialang.org/t/test-for-a-zero-valued-tuple-in-where-statement/97579 "2023-04-17T21:52:14Z")

</div>

I would like to have a special dispatch for the case that a Tuple{} in the type definition is zero (in all entries). For example: foo(a::AbstractArray{T, N}) where {N, T\<:Tuple{zeros(Int,N)...}} but get an error since N…

---

## [Canonical Julian way to represent multiple implementations of same algorithm](https://discourse.julialang.org/t/canonical-julian-way-to-represent-multiple-implementations-of-same-algorithm/97312)

<div class="topic-metadata">

**Author:** [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Replies:** 7\
**Last updated:** [April 10, 2023, 8:35pm UTC](https://discourse.julialang.org/t/canonical-julian-way-to-represent-multiple-implementations-of-same-algorithm/97312 "2023-04-10T20:35:24Z")

</div>

Suppose I have some number of different implementations of the same algorithm, or more generally just multiple implementations meeting the same requirements (i.e. identical inputs give identical outputs, modulo usual flo…

---

## [What is a good way to write methods that help the user not mix up input order?](https://discourse.julialang.org/t/what-is-a-good-way-to-write-methods-that-help-the-user-not-mix-up-input-order/94803)

<div class="topic-metadata">

**Author:** [@philip](https://discourse.julialang.org/u/philip)\
**Replies:** 7\
**Last updated:** [February 23, 2023, 4:04am UTC](https://discourse.julialang.org/t/what-is-a-good-way-to-write-methods-that-help-the-user-not-mix-up-input-order/94803 "2023-02-23T04:04:47Z")

</div>

I’ve often encountered issues similar to Keyword argument types - what's going on? - #11 by sijo . I like to write methods with keyword arguments because I find them harder to silently screw up calling than positional ar…

---

## [Dispatch surprise with vectors](https://discourse.julialang.org/t/dispatch-surprise-with-vectors/94214)

<div class="topic-metadata">

**Author:** [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Replies:** 2\
**Last updated:** [February 7, 2023, 2:58pm UTC](https://discourse.julialang.org/t/dispatch-surprise-with-vectors/94214 "2023-02-07T14:58:09Z")

</div>

I’ve been trying to implement some functions taking advantage of some default values as well as multiple dispatch and I stumbled upon the following behavior. It is surprising to me but maybe it is just the way things wor…

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