(afaik requires @generated functions to take everything to a type stable post-precompilation state)
assuming (a1) If `typeof(x) == typeof(y)` then `typeof( t(x) )` is the same as `typeof( t(y) )`. (a2) If `typeof(x) != typeof(y)` then `typeof( t(x) )` might differ from `typeof( t(y) )`. (a3) There are relatively few (dozens not millions) possible types that x may have when `t(x)` is called. (b1) If `typeof(x) == typeof(y)` then `typeof( f2(x) )` is the same as `typeof( t(y) )`. (b2) If `T is the typeof(x) and T != typeof(y)`, `typeof( f2(t, a::Vector{typeof(x)}) )` may differ from `typeof( f2(t, a::Vector{typeof(y)}) )`. (b2) There are relatively few (dozens not millions) possible types that T may have when `f2{T}(t, a::Vector{T})` is called. Given (a123), If you write one version of the function `t` for each [abstract] type of x that is to be processed, you could annotate each of them with the correct return type. If you can do that, then you could create an ObjectIdDict, t_oid, that maps the type of `x` to the return type of `t`. Given (b123) and t_oid, you can create an ObjectIdDict, f2_oid, that maps the type `T` in `f2` to the return type of `f2`. Using t_oid and f2_oid the return type for each call of `t` and each call of `f2` is determinate and available. On Monday, November 14, 2016 at 5:32:51 PM UTC-5, bogumil....@gmail.com wrote: > > Actually I could do: > > function f2{T}(t, a::Vector{T}) > Dict{T, code_typed(t, (T,))[1].rettype}((x, t(x)) for x in a) > end > > but this does not solve the problem as the compiler still is unable to > determine the exact return type of f2. > > On Monday, November 14, 2016 at 4:06:20 PM UTC+1, Lutfullah Tomak wrote: >> >> You could find `ta=t.(a)` first and then construct a >> `Dict{eltype(a),eltype(ta)}` but it is just a workaround and wastes some >> memory. > >