# Parametric structures and Inner constructors that don't depend on the types

**URL:** <https://discourse.julialang.org/t/parametric-structures-and-inner-constructors-that-dont-depend-on-the-types/127459>\
**Category:** General Usage\
**Tags:** constructors\
**Created:** [March 28, 2025, 3:06pm UTC](https://discourse.julialang.org/t/parametric-structures-and-inner-constructors-that-dont-depend-on-the-types/127459 "2025-03-28T15:06:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [March 28, 2025, 3:06pm UTC](https://discourse.julialang.org/t/parametric-structures-and-inner-constructors-that-dont-depend-on-the-types/127459/1 "2025-03-28T15:06:36Z")

</div>

Hi all, I apologize for the title which is not clear at all, but I don’t know how to properly express my need concisely.

I currently try to define a parametric `struct` for which the inner constructor doesn’t depend on the types defined when declaring the fields.

Here is a MWE

```julia
struct MyStruct{T <: AbstractRange}
   t :: T

   function Mystruct(a) where T
      t = a:3a
      return new{T}(t)
   end
end

```

When I create an instance of `MyStruct` such as `ms = MyStruct(2)`, I receive the following error:

```julia
UndefVarError: `T` not defined in static parameter matching
Suggestion: run Test.detect_unbound_args to detect method arguments that do not fully constrain a type parameter.

```

While I understand why the error is raised, I have no idea how to solve it.

Do you have any tips ?

Thank you

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [March 28, 2025, 3:23pm UTC](https://discourse.julialang.org/t/parametric-structures-and-inner-constructors-that-dont-depend-on-the-types/127459/3 "2025-03-28T15:23:01Z")

</div>

```julia
struct MyStruct{T <: AbstractRange}
    t :: T

    function MyStruct(a)
        t = a:3a
        return new{typeof(t)}(t)
    end
end

```

```julia-repl
julia> MyStruct(5)
MyStruct{UnitRange{Int64}}(5:15)

```

---

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [March 28, 2025, 5:24pm UTC](https://discourse.julialang.org/t/parametric-structures-and-inner-constructors-that-dont-depend-on-the-types/127459/4 "2025-03-28T17:24:05Z")

</div>

A big thank you @barucden
