Extracting parametric types

Hi,
I have an object defined as A = LinearOperator{Float64}(2,2,1000,:D0,:D0,[-1,-1])
so when I do typeof(A), I get
PDEOperators.LinearOperator{Float64,SVector{3,Float64},:D0,:D1} (doing this with inner constructors and all)
so now I want to extract the :D0 and :D1.
is it possible without string manipulations ie. using features of the language itself?

1 Like

Solved by @oxinabox on gitter.

julia> typeof(typeof(A).parameters)
SimpleVector

so doing

julia> typeof(A).parameters[end]
:D0

we get the required parameter.

But note that this is not type stable as SimpleVector has no type information on its contents. Thus, if possible, it is better (and more Julian) to use parametrized functions:

get_D0_D1{A,B,C,D}(::LinearOperator{A,B,C,D}) = C,D
5 Likes