How to enforce parametric types parameters in this case?

Hello.

Since Normal{Float64} <: UnivariateDistribution I would like to enforce that a Distribution field has a type parameter identical to the type of another field. Let me show you an example that does not work:

using Distributions
struct Foo{T<:Real, D{T} <: UnivariateDistribution}
    x::T
    d::D
end

So that if x is a Float32, d cannot be a Normal{Float64} but can be a Uniform{Float32}.
How do I do that with a valid definition ?

Generally

  1. constructors are recommended for checking constraints,
  2. it is not a good idea to rely on type parameters — use the API for those things.