abstract type DEF{super<:Tuple}
struct X <: DEF{Tuple{F,Y,Z{Int}}}
end
I want to access the supertype of X which is DEF
and specifically what types are in the tuple Tuple{F,Y,Z{Int}}}
F, Y and Z{Int} as types
How can i do that?
when creating a method that does something with variables of type X you need to include a where clause in the method signature so that Julia knows how to branch off different types. Here is a minimally working example:
abstract type DEF{Super <: Tuple}
end #even abstract type definitions need an end
#note the type parameters for X, they tell the compiler that F, Y, and Z are typevars and not existing types
struct X{F,Y, Z} <: DEF{Tuple{F, Y, Z} }
end
function does_something(x::X{F,Y, Z}) where {F, Y, Z}
println("F is an $F, Y is a $Y, Z is a $Z") #use F, Y, and Z like any normal type
z = Z() # a variable of type Z, assuming it has an appropriate constructor
end
These are implementation details, and accessing them is not good style (they may change without warning or deprecation).
Within functions, the approach suggested by @Philip_Stuckey above is best, but if the parameter is needed explicitly, it can be extracted with a function like
Well, one could argue that you shouldn’t handle type parameters when you don’t know what they stand for. Translated to your problem: you should enumerate the different possibilities. Otherwise, does post 3 not work?