# Subtyping with Parametric Abstract Types

I don’t understand why

``````struct MultiDist{D <: UnivariateDistribution{S <: ValueSupport}} <: MultivariateDistribution{S <: ValueSupport}
dist::D
n::Int
end
``````

returns that S in undefined. I also tried

``````struct MultiDist{D <: UnivariateDistribution{S}} <: MultivariateDistribution{S} where S <: ValueSupport
dist::D
n::Int
end
``````

isn’t …

``````julia> Sampleable{Univariate,Discrete} <: Sampleable{Multivariate,Discrete}
false

julia> Sampleable{Univariate,Continuous} <: Sampleable{Multivariate,Continuous}
false

julia> Distribution{Univariate,Discrete} <: Distribution{Multivariate,Discrete}
false

julia> Distribution{Univariate,Continuous} <: Distribution{Multivariate,Continuous}
false
``````

what are you trying to achieve?

MultiDist is a struct that is a `MultivariateDistribution`. One of the fields of that struct, `dist`, is a `UnivariateDistribution`. Both should have the same `ValueSupport`, either `Continuous` or `Discrete`. At no point in my example do I imply one of the
relations you wrote.

sorry, then I misunderstood you.

Because you need to define `S` as a type parameter in order to use it, i.e. `MultiIDist{S <: ValueSupport, ...}`. Except in special cases like declaration of type parameter and declaration of type, `<:` doesn’t automatically declare a type parameter, the `S <: ValueSupport` in your code is simply an expression and the value of that expression is being applied to the type.

1 Like