# Kwarg depending on type of another kwarg

**URL:** https://discourse.julialang.org/t/kwarg-depending-on-type-of-another-kwarg/90035
**Category:** General Usage
**Tags:** function
**Created:** [November 10, 2022, 8:08am UTC](https://discourse.julialang.org/t/kwarg-depending-on-type-of-another-kwarg/90035 "2022-11-10T08:08:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [November 10, 2022, 8:08am UTC](https://discourse.julialang.org/t/kwarg-depending-on-type-of-another-kwarg/90035/1 "2022-11-10T08:08:48Z")

</div>

I want to define a keyword argument that depends on the type of another keyword argument. For example,

```julia
function testf(c; a::A = 0.0, b::NTuple{2, Type{A}} = (A, A)) where A end 

```

This is not possible, though:

```julia
julia> testf(0.0)
ERROR: UndefVarError: A not defined

```

Is there anyway to get around this? Even defining all the keyword arguments fails:

```julia
testf(0.0; a=0.0, b=(Float64, Float64))

```

```julia
julia> testf(0.0;a=0.0,b=(Float64,Float64))
ERROR: MethodError: no method matching var"#testf#97"(::Float64, ::Tuple{DataType, DataType}, ::typeof(testf), ::Float64)
Closest candidates are:
  var"#testf#97"(::A, ::Tuple{Type{A}, Type{A}}, ::typeof(testf), ::Any) where A

```

---

<div class="post-metadata">

### Author: ![tpolakovic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tpolakovic/32/8612_2.png) [@tpolakovic](https://discourse.julialang.org/u/tpolakovic)
#### Post date: [November 10, 2022, 11:38pm UTC](https://discourse.julialang.org/t/kwarg-depending-on-type-of-another-kwarg/90035/2 "2022-11-10T23:38:24Z")

</div>

`A` is a `DataType`, so the signature ~~`b::NTuple{2, Type{A}} = (A, A)` doesn’t really make sense.~~ Actually, it kinda does, but still doesn’t work because the `Type{A}` is not a concrete type.

If you do

```julia
julia> function foo(c; a::A = 0.0, b::NTuple{2, DataType} = (typeof(a), typeof(a))) where A
    b 
end
foo (generic function with 1 method)

julia> foo(0.0)
(Float64, Float64)

```

You get what you want (I think).
