title: Avoiding type instability when slicing a tuple
body: <p>This question is an adapted version of what appeared <a href="https://julialang.zulipchat.com/#narrow/stream/225542-helpdesk/topic/type.20stable.20tuple.20indexing" rel="nofollow noreferrer">here</a> in the JuliaLang Zulip helpdesk. </p>
  
  <hr>
  
  <p>Suppose I have a function that takes in a heterogeneously typed <code>Tuple</code> 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? </p>
  
  <p>For example, suppose my function is</p>
  
  <pre><code>function f(t::Tuple, A::Array{T, N}) where {T, N}
      if T &lt;: AbstractFloat
          imin = 1
      elseif T &lt;: Integer
          imin = 2
      else
          imin = 3
      end
      imax = N+2    
      t[imin:imax]
  end 
  </code></pre>
  
  <p>we see that type inference only figures out that this produces a <code>Tuple</code>, not it's length or element types even though all the needed information is available at compile time?</p>
  
  <pre><code>julia&gt; 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
  </code></pre>
  
  <p>How can I write <code>f</code> such that this works?</p>