Sometimes I want to wrap a struct which has long type information in another struct. For example, I want to wrap an interpolator like this one:
julia> using Interpolations
julia> cubic_spline_interpolation(0:0.1:0.2, zeros(Float64, 3)) |> typeof
Interpolations.Extrapolation{Float64, 1, ScaledInterpolation{Float64, 1, Interpolations.BSplineInterpolation{Float64, 1, OffsetArrays.OffsetVector{Float64, Vector{Float64}}, BSpline{Cubic{Line{OnGrid}}}, Tuple{Base.OneTo{Int64}}}, BSpline{Cubic{Line{OnGrid}}}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}, BSpline{Cubic{Line{OnGrid}}}, Throw{Nothing}}
The type information is very long, so I like to get the type automatically instead of typing the long type information by hand.
struct Foo
itp::typeof(cubic_spline_interpolation(0:0.1:0.2, zeros(Float64, 3)))
something_else
end
But quite often I want a parametric type so that the interpolator can be used for real or complex numbers. Ideally, I want something like the following:
struct Foo{T}
itp::typeof(cubic_spline_interpolation(0:0.1:0.2, zeros(T, 3)))
something_else
end
But this definition won’t work, as T
is just a placeholder in this definition and thus the function call zeros(T, ...)
doesn’t work.
One solution might be
struct Foo{ITP}
itp::ITP
end
but I don’t like this one, as then the Struct Foo
would have long type information.
Is there a way to solve this problem? Thanks.