Type stability nested dictionary

I am getting a nested input dictionary as input to my code, the structure of which I’d like to preserve. It is a nested dictionary where the “end state” is always an object of the same type (which I know). See the example below.

struct examplestruct

D = Dict(

struct parentstruct

This nested dictionary D here is saved in another struct, which introduces a type stability.

Does anyone have a good way around this type instability? The input will have to remain a nested structure, but I am allowed to change that structure inside my code (for computation). However, I would like to keep some form of the nested data structure, which is needed for output.

Parametrize the type in parentstruct. See



Incidentally, please follow the style conventions and capitalize type names.


1 Like

Thanks for the reply!

However, I don’t think that would completely solve the problem here, because the type of D is Dict{Symbol,Any}? (since the level of nesting is not consistent)

I think that what you are looking for is:

struct ParentStruct{T}
    d::Dict{Symbol, T}

T can be any type, but it is not the Any type. :wink:

1 Like