# Structs with nested parametric types

**URL:** <https://discourse.julialang.org/t/structs-with-nested-parametric-types/48448>\
**Category:** General Usage\
**Tags:** parametric-types, struct\
**Created:** [October 15, 2020, 6:37pm UTC](https://discourse.julialang.org/t/structs-with-nested-parametric-types/48448 "2020-10-15T18:37:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [October 15, 2020, 6:37pm UTC](https://discourse.julialang.org/t/structs-with-nested-parametric-types/48448/1 "2020-10-15T18:37:37Z")

</div>

I’m trying to create a struct with parametric types. I want the struct to have a field of type `Array{U{F}}`, where `U<:Unitful.Length`, `F<:AbstractFloat`. Is there any way to have nested parametric types for structs in Julia?

```nohighlight
# Struct definition attempt
using Unitful
julia> s = struct{U<:Unitful.Length, F<:AbstractFloat}
           v::Array{U{F}}
       end

ERROR: syntax: invalid type signature around REPL[22]:1
s = struct

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 15, 2020, 7:03pm UTC](https://discourse.julialang.org/t/structs-with-nested-parametric-types/48448/2 "2020-10-15T19:03:44Z")

</div>

Struct definitions don’t use assignment; you haven’t given your struct a name; You’ll have to specify the type parameters of `Unitful.Length` as well, as `UnionAll`s are not allowed in a type specification:

```julia
julia> struct STRUCT_NAME{F <: AbstractFloat, U <: Unitful.Length{F}}
          v::Vector{U} # only one dimension or more needed?
       end

```

---

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [October 16, 2020, 3:22pm UTC](https://discourse.julialang.org/t/structs-with-nested-parametric-types/48448/3 "2020-10-16T15:22:22Z")

</div>

Yup this worked, when copying over the code I had accidentally left out the `STRUCT_NAME`. The line `U <: Unitful.Length{F}` was exactly what I was looking for. Thanks!
