# \#parametric-methods

**URL:** https://discourse.julialang.org/tag/parametric-methods/621.md

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

---

## [How to combine @nospecialize with type parameters?](https://discourse.julialang.org/t/how-to-combine-nospecialize-with-type-parameters/137304)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 6\
**Last updated:** [May 28, 2026, 11:29am UTC](https://discourse.julialang.org/t/how-to-combine-nospecialize-with-type-parameters/137304 "2026-05-28T11:29:20Z")

</div>

It seems that type parameters in functions prevent @nospecialize from having an effect: julia\> f(@nospecialize x::T) where T = 0; julia\> f(1); f(1.0); julia\> m = only(methods(f)); m.specializations |\> collect 7-elemen…

---

## [\[Documentation Minor Typo?\] Parametric Methods - Statement Regarding Return Type Declarations](https://discourse.julialang.org/t/documentation-minor-typo-parametric-methods-statement-regarding-return-type-declarations/135694)

<div class="topic-metadata">

**Author:** [@fincleah](https://discourse.julialang.org/u/fincleah)\
**Replies:** 0\
**Last updated:** [February 16, 2026, 10:28pm UTC](https://discourse.julialang.org/t/documentation-minor-typo-parametric-methods-statement-regarding-return-type-declarations/135694 "2026-02-16T22:28:53Z")

</div>

Hi All, I’ve been reading through the manual in order to learn Julia, and I’m on the Methods chapter. However, I think I’ve spotted a typo? It’s a very minor thing - but I think the sentence is saying that the where st…

---

## [Good way to parametrize over type parameter?](https://discourse.julialang.org/t/good-way-to-parametrize-over-type-parameter/132533)

<div class="topic-metadata">

**Author:** [@loisel](https://discourse.julialang.org/u/loisel)\
**Replies:** 4\
**Last updated:** [September 21, 2025, 12:27pm UTC](https://discourse.julialang.org/t/good-way-to-parametrize-over-type-parameter/132533 "2025-09-21T12:27:28Z")

</div>

Hi, I’m writing a numerical code that is parametrized by T, which is typically T=Float64 but could be one of the other number types. It’s a PDE solver so I’ve got a bunch of other types I call “geometries”, say A{T}, B{…

---

## [Notice: a subtle footgun: UnionAll type variable order + method static parameter normalization](https://discourse.julialang.org/t/notice-a-subtle-footgun-unionall-type-variable-order-method-static-parameter-normalization/113779)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 2\
**Last updated:** [January 31, 2025, 10:12am UTC](https://discourse.julialang.org/t/notice-a-subtle-footgun-unionall-type-variable-order-method-static-parameter-normalization/113779 "2025-01-31T10:12:47Z")

</div>

Consider this snippet: id(::Type{T}) where {T} = T some\_type{7,Int} == id(some\_type){7,Int} Naively, it seems like the comparison on the second line should return true for any type some\_type, assuming neither type appl…

---

## [Any workaround for this core Julia bug causing spurious \`UndefVarError\`?](https://discourse.julialang.org/t/any-workaround-for-this-core-julia-bug-causing-spurious-undefvarerror/109083)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 0\
**Last updated:** [January 22, 2024, 6:45am UTC](https://discourse.julialang.org/t/any-workaround-for-this-core-julia-bug-causing-spurious-undefvarerror/109083 "2024-01-22T06:45:14Z")

</div>

This script succeeds as expected (run as script or try in a fresh REPL session): f(::Type{\<:Tuple{Vararg{A}}}) where {A} = A struct S end f(Tuple{Vararg{S}}) f(Tuple{Vararg{T}} where {T\<:S}) But if the order of the c…

---

## [How does instance of a type works/interact with type parameters?](https://discourse.julialang.org/t/how-does-instance-of-a-type-works-interact-with-type-parameters/104475)

<div class="topic-metadata">

**Author:** [@EricH](https://discourse.julialang.org/u/EricH)\
**Replies:** 11\
**Last updated:** [October 15, 2023, 11:14pm UTC](https://discourse.julialang.org/t/how-does-instance-of-a-type-works-interact-with-type-parameters/104475 "2023-10-15T23:14:48Z")

</div>

Hi everyone, I am studying the code from repo ReinforcementLearningAnIntroduction.jl. In notebook Chapter01\_Tic\_Tac\_Toe.jl, there is this line that confuses me E = DefaultStateStyleEnv{Observation{Int}()}(env) Why ca…

---

## [Question on manual subsection: Extracting the type parameter from a super-type](https://discourse.julialang.org/t/question-on-manual-subsection-extracting-the-type-parameter-from-a-super-type/97137)

<div class="topic-metadata">

**Author:** [@aafsar](https://discourse.julialang.org/u/aafsar)\
**Replies:** 4\
**Last updated:** [April 6, 2023, 12:10pm UTC](https://discourse.julialang.org/t/question-on-manual-subsection-extracting-the-type-parameter-from-a-super-type/97137 "2023-04-06T12:10:41Z")

</div>

Question: One correct and two wrong code templates for extracting the type parameter from a super-type is provided in this subsection of the manual. I don’t understand how the “correct template” doesn’t fail for the arg…

---

## [Best practice for passing parameters to functions passed as parameters](https://discourse.julialang.org/t/best-practice-for-passing-parameters-to-functions-passed-as-parameters/85479)

<div class="topic-metadata">

**Author:** [@nsquare](https://discourse.julialang.org/u/nsquare)\
**Replies:** 5\
**Last updated:** [August 9, 2022, 3:47pm UTC](https://discourse.julialang.org/t/best-practice-for-passing-parameters-to-functions-passed-as-parameters/85479 "2022-08-09T15:47:13Z")

</div>

Hello! I want to write a general function with several subroutines. I would like this method to be able to use different functions as subroutines, by taking them as parameters, as shown in the toy example below. functi…

---

## [Why isn't this type signature allowed?](https://discourse.julialang.org/t/why-isnt-this-type-signature-allowed/85170)

<div class="topic-metadata">

**Author:** [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Replies:** 18\
**Last updated:** [August 2, 2022, 7:30pm UTC](https://discourse.julialang.org/t/why-isnt-this-type-signature-allowed/85170 "2022-08-02T19:30:58Z")

</div>

Given that functions f, g, and h all work, why isn’t function i allowed? Shouldn’t i work like an alias for g just like h does? x = 1 y = 0.1 function f(x::Number, y::Number) return "This is function f." end functi…

---

## [Which of \`::\` and \`where\` should take precedence?](https://discourse.julialang.org/t/which-of-and-where-should-take-precedence/84807)

<div class="topic-metadata">

**Author:** [@shaowei](https://discourse.julialang.org/u/shaowei)\
**Replies:** 4\
**Last updated:** [July 27, 2022, 5:11am UTC](https://discourse.julialang.org/t/which-of-and-where-should-take-precedence/84807 "2022-07-27T05:11:39Z")

</div>

Currently (Julia v1.7), where takes precedence over ::. For example: julia\> :(f(x::T where T \<: Integer)) :(f(x::(T where T \<: Integer))) However, this means that the return type annotation will not play nice with para…

---

## [Destructuring Type Parameters](https://discourse.julialang.org/t/destructuring-type-parameters/81881)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 3\
**Last updated:** [May 29, 2022, 11:43pm UTC](https://discourse.julialang.org/t/destructuring-type-parameters/81881 "2022-05-29T23:43:57Z")

</div>

Is there any way to destructure type parameters when defining parametric types and methods. Something along the lines of struct Foo{U{T}} end # Examples Foo{Vector{Int}}() Foo{AbstractArray{Int}}() I know this parti…

---

## [Extracting type parameters from type with many parameters](https://discourse.julialang.org/t/extracting-type-parameters-from-type-with-many-parameters/81843)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 6\
**Last updated:** [May 29, 2022, 12:07am UTC](https://discourse.julialang.org/t/extracting-type-parameters-from-type-with-many-parameters/81843 "2022-05-29T00:07:05Z")

</div>

I’ve got a type with six type parameters, something like this: struct MyType{A \<: S, a0, a1, B \<: T, b0, b1} end My problem is that I want access to the type parameters in functions which take MyType values as argument…

---

## [Can \`where\` constrain type parameters that are instances, like \`where {T isa Symbol}\`](https://discourse.julialang.org/t/can-where-constrain-type-parameters-that-are-instances-like-where-t-isa-symbol/81443)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 6\
**Last updated:** [May 22, 2022, 6:56pm UTC](https://discourse.julialang.org/t/can-where-constrain-type-parameters-that-are-instances-like-where-t-isa-symbol/81443 "2022-05-22T18:56:43Z")

</div>

where clauses can constrain type parameters that are types e.g. where T \<: Number, but I’m interested in constraining instances e.g. where T isa Symbol vs. where T isa Integer, which is not valid syntax. Is there a way t…

---

## [Unexpected ambigiuity in subtype constructor](https://discourse.julialang.org/t/unexpected-ambigiuity-in-subtype-constructor/80475)

<div class="topic-metadata">

**Author:** [@sjrodahl](https://discourse.julialang.org/u/sjrodahl)\
**Replies:** 2\
**Last updated:** [May 4, 2022, 12:21pm UTC](https://discourse.julialang.org/t/unexpected-ambigiuity-in-subtype-constructor/80475 "2022-05-04T12:21:00Z")

</div>

Consider this example: julia\> abstract type AbstractT end julia\> struct A \<: AbstractT i::Int end julia\> struct Param myparam::Int end julia\> (::Type{T})(p::Param) where T\<:AbstractT …

---

## [Getting function signature expression from method instance](https://discourse.julialang.org/t/getting-function-signature-expression-from-method-instance/71639)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 0\
**Last updated:** [November 17, 2021, 9:08am UTC](https://discourse.julialang.org/t/getting-function-signature-expression-from-method-instance/71639 "2021-11-17T09:08:20Z")

</div>

Is there an existing function to get a method definition expression from the Method instance? As example, I would like to have some function signature\_expression such that: ff(a::T, b::C, c::Tuple{Real,Real}) where {T \<…

---

## [How to create convenient single-parametric types with multiple fields](https://discourse.julialang.org/t/how-to-create-convenient-single-parametric-types-with-multiple-fields/59166)

<div class="topic-metadata">

**Author:** [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Replies:** 3\
**Last updated:** [April 13, 2021, 12:02pm UTC](https://discourse.julialang.org/t/how-to-create-convenient-single-parametric-types-with-multiple-fields/59166 "2021-04-13T12:02:42Z")

</div>

Hello everyone! MWE I have a parametric type as follows: struct Foster\_Π{T \<: Number} zero\_zero::Bool H::T ω\_z::Vector{T} ω\_p::Vector{T} end I tried at first having a non-parametric type with everythin…

---

## [Invoke different method for callable struct / How to emulate pythons \`super()\`](https://discourse.julialang.org/t/invoke-different-method-for-callable-struct-how-to-emulate-pythons-super/57869)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 4\
**Last updated:** [March 24, 2021, 5:01pm UTC](https://discourse.julialang.org/t/invoke-different-method-for-callable-struct-how-to-emulate-pythons-super/57869 "2021-03-24T17:01:46Z")

</div>

I have a parametric function as discussed here and now want to generate another such function type that logs its arguments while invoking the non-logging method for the computation. How do I use invoke to dispatch on the…

---

## [Method matching an array with elements of a composite type with parametric types](https://discourse.julialang.org/t/method-matching-an-array-with-elements-of-a-composite-type-with-parametric-types/56271)

<div class="topic-metadata">

**Author:** [@mroavi](https://discourse.julialang.org/u/mroavi)\
**Replies:** 8\
**Last updated:** [March 4, 2021, 9:32am UTC](https://discourse.julialang.org/t/method-matching-an-array-with-elements-of-a-composite-type-with-parametric-types/56271 "2021-03-04T09:32:29Z")

</div>

Here is my composite type: mutable struct Factor{T, N} vars::NTuple{N,Int64} vals::Array{T,N} end How can I define a method that matches arrays with elements of this type and that can access the parametric type T? …
