This question is an adapted version of what appeared here in the JuliaLang Zulip helpdesk.
Suppose I have a function that takes in a heterogeneously typed Tuple and will return a slice of that tuple where the slice indices may be statically inferred from only type information. How can I write my function in such a way that the output type is correctly inferred?
For example, suppose my function is
function f(t::Tuple, A::Array{T, N}) where {T, N}
if T <: AbstractFloat
imin = 1
elseif T <: Integer
imin = 2
else
imin = 3
end
imax = N+2
t[imin:imax]
end
we see that type inference only figures out that this produces a Tuple, not it's length or element types even though all the needed information is available at compile time?
julia> let t = (:a, "b", 2, 3.0, Val(1), 2+im), A = rand(Int, 3,3)
Base.return_types(f, Tuple{typeof(t), typeof(A)})
end
1-element Array{Any,1}:
Tuple
How can I write f such that this works?