On Fri, Apr 22, 2016 at 9:02 AM, Milan Bouchet-Valat <[email protected]> wrote:
> Hi! Yet more explorations regarding inference and varargs/tuple
> arguments.
>
> I have a function taking a tuple of vectors, and I need a way to
> extract the element types of each of them, in order to create a Dict.
> The following code works fine, but inference is not able to compute T
> at compile time:
> function f(x::Tuple)
> T = Tuple{map(eltype, x)...}
> Dict{T,Int}()
> end
>
> @code_warntype f(([1,2], [1.,2.],))
>
> The same happens with varargs, i.e. f(x...).
>
> Is there any solution to this (other than generated functions)? Am I
> missing an existing bug report again?
This is the case `@pure` is replacing `@generated` on 0.5-dev (More
flexible type computation without non-trivial code generation)
```
julia> Base.@pure f(x) = Tuple{map(eltype, x.parameters)...}
f (generic function with 1 method)
julia> function g(x::Tuple)
Dict{f(typeof(x)),Int}()
end
g (generic function with 1 method)
julia> @code_warntype g(([1, 2], [1., 2.]))
Variables:
#self#::#g
x::Tuple{Array{Int64,1},Array{Float64,1}}
Body:
begin # REPL[2], line 2:
return
(Dict{Tuple{Int64,Float64},Int64})()::Dict{Tuple{Int64,Float64},Int64}
end::Dict{Tuple{Int64,Float64},Int64}
```
>
> Thanks!