# Help defining a parametric type

**URL:** <https://discourse.julialang.org/t/help-defining-a-parametric-type/17419>\
**Category:** General Usage\
**Tags:** parametric-types\
**Created:** [November 12, 2018, 3:25am UTC](https://discourse.julialang.org/t/help-defining-a-parametric-type/17419 "2018-11-12T03:25:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [November 12, 2018, 3:25am UTC](https://discourse.julialang.org/t/help-defining-a-parametric-type/17419/1 "2018-11-12T03:25:33Z")

</div>

I want to define a `mutable struct`:

```julia
mutable struct W{T <: Real}
    a::T
    b::T
    c::T
    
    W(a, b, c) = begin
                # some checks on a, b, c
                new{T}(a, b, c)
    end
end

```

When I go to create an instance I get an error:

```julia
P = W(0.5, 0.5, 0.5)
UndefVarError: T not defined

```

What’s happening?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 12, 2018, 3:31am UTC](https://discourse.julialang.org/t/help-defining-a-parametric-type/17419/2 "2018-11-12T03:31:12Z")

</div>

> [@amrods](#):
>
> What’s happening?

You need a `T` type parameter on the constructor.

---

<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:** [November 12, 2018, 6:43am UTC](https://discourse.julialang.org/t/help-defining-a-parametric-type/17419/3 "2018-11-12T06:43:49Z")

</div>

Also, for this specific problem, there is no reason to define an inner constructor; the constructors provided by the language as default should work fine. See [parametric constructors](https://docs.julialang.org/en/v1/manual/constructors/#Parametric-Constructors-1).

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [November 12, 2018, 10:17am UTC](https://discourse.julialang.org/t/help-defining-a-parametric-type/17419/4 "2018-11-12T10:17:47Z")

</div>

Thanks, I didn’t include those tests on a, b, c in the comment of my code. I need to check that a, b, c are positive and less than one, otherwise throw an error:

```julia
if 0 < a < 1 && 0 < b < 1 && 0 < c < 1
    new{T}(a, b, c)
else
    error("a, b, c must be positive and less than 1")
end

```
