# Making a custom distribution with value as parametric type

**URL:** <https://discourse.julialang.org/t/making-a-custom-distribution-with-value-as-parametric-type/57454>\
**Category:** General Usage\
**Tags:** parametric-types\
**Created:** [March 18, 2021, 10:07am UTC](https://discourse.julialang.org/t/making-a-custom-distribution-with-value-as-parametric-type/57454 "2021-03-18T10:07:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [March 18, 2021, 10:07am UTC](https://discourse.julialang.org/t/making-a-custom-distribution-with-value-as-parametric-type/57454/1 "2021-03-18T10:07:50Z")

</div>

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:

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

```

but

```julia
julia> A{0.4}(10)
ERROR: MethodError: no method matching A(::Normal{Float64})
Stacktrace:
 [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 ?

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [March 18, 2021, 10:29am UTC](https://discourse.julialang.org/t/making-a-custom-distribution-with-value-as-parametric-type/57454/2 "2021-03-18T10:29:04Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [March 18, 2021, 10:38am UTC](https://discourse.julialang.org/t/making-a-custom-distribution-with-value-as-parametric-type/57454/3 "2021-03-18T10:38:26Z")

</div>

Sweet thank you !
