# \#val

**URL:** https://discourse.julialang.org/tag/val/582.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 …

---

## [Static call at runtime](https://discourse.julialang.org/t/static-call-at-runtime/134516)

<div class="topic-metadata">

**Author:** [@epilliat](https://discourse.julialang.org/u/epilliat)\
**Replies:** 7\
**Last updated:** [December 14, 2025, 9:55am UTC](https://discourse.julialang.org/t/static-call-at-runtime/134516 "2025-12-14T09:55:56Z")

</div>

This problem comes from several pieces of code I’ve been struggling to optimize due to missunderstanding of Julia compiler. I would like to know if there are any “standard” way to do this. Consider a function f that doe…

---

## [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…

---

## [How to constraint the inner type of \`Val\` by an abstract type](https://discourse.julialang.org/t/how-to-constraint-the-inner-type-of-val-by-an-abstract-type/125944)

<div class="topic-metadata">

**Author:** [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)\
**Replies:** 4\
**Last updated:** [February 16, 2025, 4:25am UTC](https://discourse.julialang.org/t/how-to-constraint-the-inner-type-of-val-by-an-abstract-type/125944 "2025-02-16T04:25:20Z")

</div>

How can I constraint the parametric type within Val by an abstract type? Consider the following function using Unitful: Frequency, Hz function foo(q::Val{Q}) where Q \<: Frequency return q end I’d like to Q to be …

---

## [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…

---

## [Would it be possible to infer \`Val{::Bool)\` as \`Union{Val{true}, Val{false}}\`?](https://discourse.julialang.org/t/would-it-be-possible-to-infer-val-bool-as-union-val-true-val-false/94728)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [February 20, 2023, 8:25am UTC](https://discourse.julialang.org/t/would-it-be-possible-to-infer-val-bool-as-union-val-true-val-false/94728 "2023-02-20T08:25:05Z")

</div>

Consider the function julia\> f(x::Bool) = Val(x) f (generic function with 1 method) julia\> @code\_typed f(true) CodeInfo( 1 ─ %1 = Core.apply\_type(Base.Val, x)::Type{Val{\_A}} where \_A │ %2 = %new(%1)::Val └── ret…

---

## [What causes this performance loss when using value types?](https://discourse.julialang.org/t/what-causes-this-performance-loss-when-using-value-types/94065)

<div class="topic-metadata">

**Author:** [@akrishnamoorthy](https://discourse.julialang.org/u/akrishnamoorthy)\
**Replies:** 3\
**Last updated:** [February 10, 2023, 11:50pm UTC](https://discourse.julialang.org/t/what-causes-this-performance-loss-when-using-value-types/94065 "2023-02-10T23:50:42Z")

</div>

The following are two implementations of the factorial function: fact1(n) = fact1(Val(n)) fact1(::Val{n}) where {n} = n\*fact1(Val(n-1)) fact1(::Val{1}) = 1 and fact2(n) = n==1 ? 1 : n\*fact2(n-1) This may be subjectiv…

---

## [Allocations due to Boolean keyword arguments - how to avoid them?](https://discourse.julialang.org/t/allocations-due-to-boolean-keyword-arguments-how-to-avoid-them/87654)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 9\
**Last updated:** [September 22, 2022, 6:00pm UTC](https://discourse.julialang.org/t/allocations-due-to-boolean-keyword-arguments-how-to-avoid-them/87654 "2022-09-22T18:00:08Z")

</div>

Deep in one of my projects I have a function that slightly changes behavior depending on a boolean keyword. It seems if the keyword is Val{Bool} there are no allocations but if it is Bool, then it allocates. Here is a co…

---

## [\[ANN\] ValSplit.jl: Compile away dynamic dispatch on Val-typed arguments](https://discourse.julialang.org/t/ann-valsplit-jl-compile-away-dynamic-dispatch-on-val-typed-arguments/77096)

<div class="topic-metadata">

**Author:** [@Xuan](https://discourse.julialang.org/u/Xuan)\
**Replies:** 3\
**Last updated:** [March 1, 2022, 6:48pm UTC](https://discourse.julialang.org/t/ann-valsplit-jl-compile-away-dynamic-dispatch-on-val-typed-arguments/77096 "2022-03-01T18:48:33Z")

</div>

Ever wanted to use methods with Val-typed arguments, but avoid dynamic dispatch? Here’s a little package I worked on over the past week that allows you to do just that! ValSplit.jl provides the @valsplit macro, which co…

---

## [Is this design pattern of \`::Val{}\` dispatching evil?](https://discourse.julialang.org/t/is-this-design-pattern-of-val-dispatching-evil/54365)

<div class="topic-metadata">

**Author:** [@korsbo](https://discourse.julialang.org/u/korsbo)\
**Replies:** 10\
**Last updated:** [February 25, 2022, 10:25pm UTC](https://discourse.julialang.org/t/is-this-design-pattern-of-val-dispatching-evil/54365 "2022-02-25T22:25:02Z")

</div>

I’d like some feedback on a seemingly functional design involving recursion and a whole lot of ::Val{} overloads. I think that my time in the Julia community has conditioned me to shy away from such dispatching and proba…

---

## [\[ANN\] ArgumentModes.jl - an implementation of set-of-symbols like type for function arguments](https://discourse.julialang.org/t/ann-argumentmodes-jl-an-implementation-of-set-of-symbols-like-type-for-function-arguments/71429)

<div class="topic-metadata">

**Author:** [@Icarus](https://discourse.julialang.org/u/Icarus)\
**Replies:** 0\
**Last updated:** [November 13, 2021, 1:10pm UTC](https://discourse.julialang.org/t/ann-argumentmodes-jl-an-implementation-of-set-of-symbols-like-type-for-function-arguments/71429 "2021-11-13T13:10:36Z")

</div>

I’d like to announce the package ArgumentModes.jl (also available in the registry) which provides type Mode for usage as a function argument type and in function calls. Conceptually it is similar to Val type, but working…
