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

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.

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

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

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

and implement dynamic size checks.

Or you go this route:

mutable struct Example2{T1 <: Tuple, T2 <: Tuple}
    somedict::Dict{Tuple{T1, T2}, Float64}
end
2 Likes

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!!