function f(x) if x < 0 return 0 end return expensive_function(x) end
Is not type-stable (in most cases). Is there a clean way to make it stable and generic, while staying performant for
x < 0 ? The most straightforward thing I see would be to replace
return 0 with
but this does evaluate
expensive_function(x) as far as I can tell.
I saw in this question, that it is not easy to get the return type of a function without evaluating it. Now I don’t want to use the type in the code, I just want
f to be type stable and performant for
x < 0. Is this possible, assuming
expensive_function(x) is type-stable?