How to enforce parametric types parameters in this case?


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}

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 ?


  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.