# How to declare type/size of tuple in a struct?

**URL:** <https://discourse.julialang.org/t/how-to-declare-type-size-of-tuple-in-a-struct/69833>\
**Category:** General Usage\
**Created:** [October 15, 2021, 3:27pm UTC](https://discourse.julialang.org/t/how-to-declare-type-size-of-tuple-in-a-struct/69833 "2021-10-15T15:27:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [October 15, 2021, 3:27pm UTC](https://discourse.julialang.org/t/how-to-declare-type-size-of-tuple-in-a-struct/69833/1 "2021-10-15T15:27:08Z")

</div>

Hi,

I have a struct such as below. I want to know how to declare the type of the field `somedict`.  
The keys of `somedict` will be tuples. Each key will be a tuple of two tuples, first one of length `size1` and second one of length `size2`. When I create the struct instance, I want to pass the values of `size1` and `size2`. Is this possible to do? If yes, can you please give an example. If not, I would appreciate knowing that too, so that I don’t spend too much time looking for it.

Thank you.

```julia
mutable struct Example
    size1::Int64
    size2::Int64
    somedict:: ## Dict{(Tuple of size1, Tuple of size2), Float64}
end

```

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 15, 2021, 3:45pm UTC](https://discourse.julialang.org/t/how-to-declare-type-size-of-tuple-in-a-struct/69833/2 "2021-10-15T15:45:24Z")

</div>

I’m sceptical if something like this is possible because the size is not encoded in the type signature of Tuple. Of course you can use something like

```julia
mutable struct Example
    size1::Int64
    size2::Int64
    somedict::Dict{Tuple{Tuple, Tuple}, Float64}
end

```

and implement dynamic size checks.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 15, 2021, 3:48pm UTC](https://discourse.julialang.org/t/how-to-declare-type-size-of-tuple-in-a-struct/69833/3 "2021-10-15T15:48:31Z")

</div>

Or you go this route:

```julia
mutable struct Example2{T1 <: Tuple, T2 <: Tuple}
    somedict::Dict{Tuple{T1, T2}, Float64}
end

```

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [October 15, 2021, 4:23pm UTC](https://discourse.julialang.org/t/how-to-declare-type-size-of-tuple-in-a-struct/69833/4 "2021-10-15T16:23:48Z")

</div>

> [@goerch](#):
>
> ```julia
> mutable struct Example2{T1 <: Tuple, T2 <: Tuple}
> somedict::Dict{Tuple{T1, T2}, Float64}
> end
> 
> ```

Awesome! This seems like it will work. When I create the instance, it figures out the size of the tuple and the type of contents. I thought this would not be the case since we don’t specify the size and type of the content when declaring struct. Thank you!!
