# Parametric struct without specifying type parameters

**URL:** <https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418>\
**Category:** General Usage\
**Tags:** parametric-types\
**Created:** [October 24, 2025, 6:19pm UTC](https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418 "2025-10-24T18:19:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnomotani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnomotani/32/26753_2.png) [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Post date:** [October 24, 2025, 6:19pm UTC](https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418/1 "2025-10-24T18:19:04Z")

</div>

Maybe it’s a bad pattern (opinions?), but I somewhat frequently find myself creating structs to hold many parameters, where each parameter might have a couple of types and as the struct is only used within my own code, I’m not worried about strictly specifying exactly what types are allowed. So something like

```julia-auto
struct Foo{T1,T2,T3}
    x::T1
    y::T2
    z::T3
end

```

but with maybe 20-30 type parameters. Those structs can be painful to maintain, for example if I want to add a new parameter in the middle of the struct, and keep the same numbering convention, I’d have to re-number all the following type parameters.

I wrote a macro to implicitly add type parameters to any fields without an explicit type - is this a crazy thing to do? Are there any drawbacks/gotchas that I’m not seeing? It would let me write

```julia-auto
@autotyped struct FooAuto
    x
    y
    z
end

```

where that would be equivalent to `Foo`.

The code is fairly simple: [GitHub - johnomotani/AutoTypedStructs.jl: Simplify creation of Julia structs with many parametrically typed fields](https://github.com/johnomotani/AutoTypedStructs.jl)  
It also supports explicit types or type parameters if desired, for example

```julia-auto
@autotyped struct Bar{T <: Number}
    x::String
    y::T
    z
end

```

is equivalent to

```julia-auto
struct Bar{T <: Number, T1}
    x::String
    y::T
    z::T1

```

If anyone else has any interest in using this, I’ll register the package…

---

<div class="post-metadata">

**Author:** ![johnomotani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnomotani/32/26753_2.png) [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Post date:** [October 24, 2025, 6:22pm UTC](https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418/2 "2025-10-24T18:22:49Z")

</div>

Opinions on the macro/package name and suggestions for changing it are also welcome!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 24, 2025, 6:46pm UTC](https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418/3 "2025-10-24T18:46:17Z")

</div>

Have you seen [ConcreteStructs.jl](https://github.com/jonniedie/ConcreteStructs.jl)? Looks equivalent/similar.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [October 24, 2025, 7:44pm UTC](https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418/4 "2025-10-24T19:44:34Z")

</div>

> [@johnomotani](#):
>
> each parameter might have a couple of types and as the struct is only used within my own code, I’m not worried about strictly specifying exactly what types are allowed.

You’re not alone. I do that every time the intended field type is too long to type.  
If my choice is to have either

```julia-auto
struct Foo
    x::SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{Base.Slice{Base.OneTo{Int64}}}, true}
end

```

or

```julia-auto
struct Foo{T}
    x::T
end

```

I choose the latter.

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [October 27, 2025, 9:01am UTC](https://discourse.julialang.org/t/parametric-struct-without-specifying-type-parameters/133418/5 "2025-10-27T09:01:32Z")

</div>

The question has been answered, but just to add an alternative to structs altogether – sometimes I just need a one-off “bundle” of different objects and I don’t need to dispatch on it, but I want the convenience of named “fields”:

In that case I like to use `NamedTuple`s to not worry about manually typing the fields at all.
