2016-10-15 18:06 GMT-04:00 jw3126 <jw3...@gmail.com>: > myop(::Int16, ::Int16) = Int32(1) > myop(::Int16, ::Int32) = Int64(1) > myop(::Int16, ::Int64) = Int128(1) > myop(::Int16, ::Int128) = Int128(1) > > foldr(myop, Int16[1]) |> typeof |> println > foldr(myop, Int16[1,1]) |> typeof |> println > foldr(myop, Int16[1,1,1]) |> typeof |> println > foldr(myop, Int16[1,1,1,1]) |> typeof |> println > > > gives > > > Int32 > Int64 > Int128 > Int128 > > Would it be better if the answer was typestable (always Int128)? See also > here <https://github.com/JuliaLang/julia/issues/18960>. >
Yes it would be better if you implement your operation that way and no the compiler cannot do this.