I wrote some functions that shifts tuples and run into the following:
shiftleft(x1, xs...) = (xs..., x1) # (1,2,3) -> (2,3,1) shiftright1(xs...) = (xs[end], xs[1:end-1]...) # (1,2,3) -> (3,1,2) shiftright2(xs...) = (xs[end], reverse(Base.tail(reverse(xs)))...) # awkward, right? @code_typed shiftleft(1,2,3) # infers fine @code_typed shiftright1(1,2,3) # julia fails to decide the number of elements returned. @code_typed shiftright2(1,2,3) # infers fine
Generally I find it hard to spot issues when type inference works in my mind but not work in julia. Can you shed some light on me ? Many Thanks.