Type instability with tuples of functions and parameters

No, N would need to be known at compile time via the type I believe. (But I have only used @generated a very few times, so am not an expert myself, and I’ve never used @nexprs.)

One last option is to use recursion to keep splitting off one element of the tuple. As long as N is not gigantic the compiler can make it type stable:

 struct Point{T,FTup <: Tuple}
    x::T
    y::T
    F::FTup  # I'll make it a tuple of tuples to make the recursion easier
end

pt = Point(x, y, ((F1,p₁), (F2,p₂), (F3,p₃)))

function TestFnc(x,y,F,args...)
    F[1](x,y,F[2]) + TestFnc(x,y,args...)
end

function TestFnc(x,y,F)
    F[1](x,y,F[2])
end

function TestFnc(pt::Point) 
    TestFnc(pt.x,pt.y,pt.F...)
end

I think this should also be type stable.

2 Likes