# Help subtyping with Parameters.jl

**URL:** <https://discourse.julialang.org/t/help-subtyping-with-parameters-jl/5483>\
**Category:** General Usage\
**Tags:** question, type, syntax\
**Created:** [August 21, 2017, 3:45pm UTC](https://discourse.julialang.org/t/help-subtyping-with-parameters-jl/5483 "2017-08-21T15:45:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 21, 2017, 3:45pm UTC](https://discourse.julialang.org/t/help-subtyping-with-parameters-jl/5483/1 "2017-08-21T15:45:59Z")

</div>

Could you please help me fix this subtyping error, I don’t know how Parameters.jl is interacting with the code:

```julia
using Parameters: @with_kw

abstract type AbstractVariogram{T<:Real,V} end

@with_kw struct GaussianVariogram{T<:Real,V} <: AbstractVariogram{T,V}
  range::T = one(T)
  sill::V = one(V)
  nugget::V = zero(V)
end

GaussianVariogram()
ERROR: UndefVarError: T not defined

```

---

<div class="post-metadata">

**Author:** ![ohsonice](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@ohsonice](https://discourse.julialang.org/u/ohsonice)\
**Post date:** [August 21, 2017, 4:19pm UTC](https://discourse.julialang.org/t/help-subtyping-with-parameters-jl/5483/2 "2017-08-21T16:19:17Z")

</div>

In your example, would do you expect the type parameters (`T` and `V`) to be? You don’t give the constructor any information about them. Two easy fixes:

1. Give the constructor types

```julia
julia> GaussianVariogram{Int,Float64}()
GaussianVariogram{Int64,Float64}
  range: Int64 1
  sill: Float64 1.0
  nugget: Float64 0.0

```

1. Define the desired types for your default values:

```julia
julia> @with_kw struct GaussianVariogram{T<:Real,V} <: AbstractVariogram{T,V}
         range::T = one(Float64)
         sill::V = one(Int)
         nugget::V = zero(Int)
       end
GaussianVariogram

julia> GaussianVariogram()
GaussianVariogram{Float64,Int64}
  range: Float64 1.0
  sill: Int64 1
  nugget: Int64 0

```

Also, if you look at the src for Parameters.jl, the comments explain what the macro is doing: [https://github.com/mauro3/Parameters.jl/blob/87ffb34adb3555fded8cfc2227d4defd22a38be7/src/Parameters.jl#L148](https://github.com/mauro3/Parameters.jl/blob/87ffb34adb3555fded8cfc2227d4defd22a38be7/src/Parameters.jl#L148)

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 21, 2017, 4:32pm UTC](https://discourse.julialang.org/t/help-subtyping-with-parameters-jl/5483/3 "2017-08-21T16:32:08Z")

</div>

That is beautiful @ohsonice, I always miss the type information step. Thank you very much 🙂
