# How to enforce parametric types parameters in this case?

**URL:** https://discourse.julialang.org/t/how-to-enforce-parametric-types-parameters-in-this-case/38815
**Category:** General Usage
**Created:** [May 5, 2020, 3:42pm UTC](https://discourse.julialang.org/t/how-to-enforce-parametric-types-parameters-in-this-case/38815 "2020-05-05T15:42:48Z")
**Posts on this page:** 2
**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: [May 5, 2020, 3:42pm UTC](https://discourse.julialang.org/t/how-to-enforce-parametric-types-parameters-in-this-case/38815/1 "2020-05-05T15:42:48Z")

</div>

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:

```julia
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 ?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 5, 2020, 3:47pm UTC](https://discourse.julialang.org/t/how-to-enforce-parametric-types-parameters-in-this-case/38815/2 "2020-05-05T15:47:21Z")

</div>

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.
