Nice blog post. One thing I would add is that we could optimize the performance problem by peeling one iteration off the front of the loop, thereby making the rest of the loop type-stable. However, this exposes another problem with this code – the return type of the function depends on the value of n: for n ≤ 0 it returns an Int, while for n > 0 it returns a Float64. Thus, even though we could make this code run faster, any code calling this function would have to code with its poor type behavior in turn.