Making a custom distribution with value as parametric type

Hello, I’m trying to get my head around types with a value parameter. Here I’m trying to implement a wrapper to the Normal distribution type where two distributions must have the same Coefficient of Variability (CV) to be considered the same type. So I would like one of the parameters to have a type equal to the CV. Here’s what I’m trying:

using Distributions
struct A{CV,T}
       A{CV}(μ::Number) where CV = A(Normal(μ,μ*CV))


julia> A{0.4}(10)
ERROR: MethodError: no method matching A(::Normal{Float64})
 [1] A{0.4,T} where T(::Int64) at ./REPL[6]:3
 [2] top-level scope at REPL[7]:1d

Any idea how I could do this ?

You cannot use A(…) In the inner constructor, since that constructor does not exist (when you define an inner constructor, none of the “default” constructors are created). Use the new function instead. In addition, you also need to specify the second type parameter of A. This will work:

A{CV}(a::Normal{T}) where {CV,T} = new{CV,T}(a)
A{CV}(μ::Number) where CV = A{CV}(Normal(μ,μ*CV))

Sweet thank you !