# Function with argument of generic parametric type, and another argument subtyping the parameter

**URL:** <https://discourse.julialang.org/t/function-with-argument-of-generic-parametric-type-and-another-argument-subtyping-the-parameter/117813>\
**Category:** New to Julia\
**Tags:** parametric-types, functions\
**Created:** [August 4, 2024, 4:25pm UTC](https://discourse.julialang.org/t/function-with-argument-of-generic-parametric-type-and-another-argument-subtyping-the-parameter/117813 "2024-08-04T16:25:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oblomov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oblomov/32/211073_2.png) [@Oblomov](https://discourse.julialang.org/u/Oblomov)\
**Post date:** [August 4, 2024, 4:25pm UTC](https://discourse.julialang.org/t/function-with-argument-of-generic-parametric-type-and-another-argument-subtyping-the-parameter/117813/1 "2024-08-04T16:25:31Z")

</div>

Hello all,

I’m still trying to understand how generic type dependencies work in Julia. As a follow-up to [my question here](https://discourse.julialang.org/t/understanding-generic-functions-and-parametric-types/117810/3), I would like to have a dyadic function `f(a, b)` with the following conditions:

- `a` should be a vector-like of tuples (matrix-like of number, `String`)
- `b` should be of a type that subtypes.

For the type of `a`, per the above question, I’ve settled on `AbstractVector{Tuple{M, String}} where M <: AbstractMatrix{<:Number}`. This is necessary, because otherwise passing an actual `Matrix` to the function won’t work. However, this makes the actual element type for the matrix “inaccessible” to specify the type of `b`.

In the end I found out that a possible solution is to use a nested `where` specification:

```julia
f(a::AbstractVector{Tuple{M, String}}, b::S) where {M <:AbstractMatrix{T}, S<:T} where T <: Number = @show (M, S)

```

This solution works fine in this trivial case, but in practice, when type `T` is not going to be used, it will result in the following warning:

```julia
WARNING: method definition for f at cde.jl:67 declares type variable T but does not use it.

```

which I would like to avoid.

Is there a better approach to apply this kind of constraints that I’m missing?

---

<div class="post-metadata">

**Author:** ![Oblomov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oblomov/32/211073_2.png) [@Oblomov](https://discourse.julialang.org/u/Oblomov)\
**Post date:** [August 4, 2024, 4:30pm UTC](https://discourse.julialang.org/t/function-with-argument-of-generic-parametric-type-and-another-argument-subtyping-the-parameter/117813/2 "2024-08-04T16:30:14Z")

</div>

Ah, it seems that the warning arises in the case where all this type deduction happens in optional parameters

> <https://github.com/JuliaLang/julia/issues/49275>
>
> If I have a function with a nested type delegation (two \`where\`s), I get the fol…lowing incorrect warning
> 
> \`\`\`Julia
> julia\> foo(;a::T) where {T\<:AbstractVector{N}} where {N} = zero(N)
> WARNING: method definition for foo at REPL\[5\]:1 declares type variable N but does not use it.
> WARNING: method definition for foo##kw at REPL\[5\]:1 declares type variable N but does not use it.
> foo (generic function with 1 method)
> \`\`\`
> 
> It is being used, as can be seen by these two executions of the function
> \`\`\`Julia
> julia\> foo(a=\[1.0\])
> 0.0
> 
> julia\> foo(a=\[1\])
> 0
> \`\`\`
> 
> If I do something similar without nesting the type, it works fine with no warning
> \`\`\`Julia
> julia\> bar(;a::N) where {N} = zero(N)
> bar (generic function with 1 methods)
> \`\`\`
> 
> Ran on 1.8.5 and latest 1.9 RC
> \`\`\`Julia
> julia\> versioninfo()
> Julia Version 1.8.5
> Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
> Platform Info:
> OS: macOS (arm64-apple-darwin21.5.0)
> CPU: 8 × Apple M1
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
> Threads: 1 on 4 virtual cores
> \`\`\`
> \`\`\`Julia
> julia\> versioninfo()
> Julia Version 1.9.0-rc2
> Commit 72aec423c2a (2023-04-01 10:41 UTC)
> Platform Info:
> OS: macOS (arm64-apple-darwin21.3.0)
> CPU: 8 × Apple M1
> WORD\_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
> Threads: 1 on 4 virtual cores
> Environment:
> JULIA\_IMAGE\_THREADS = 1
> \`\`\`

which I think I can avoid at least in my case.
