Julia:如何避免自动促销类型更改?

Julia: How to avoid auto-promotion type changes?

例如:

n::Uint8 = 0x00
x::Uint8 = n + 0x10
ERROR: type: typeassert: expected Uint8, got Uint64

我假设发生这种情况是因为未定义 a::Uint8, b::Uint8methods(+),因此 n 自动提升为 Uint64。有没有比在每次操作后将所有内容都转换回它的预提升类型更好的方法来处理这个问题?这不是解释器应该能够自动处理的东西吗(即如果它被告知 x 应该在添加后分配 Uint8 )?

我认为在 Julia 0.3 中没有比

更好的方法了
julia> typeof(uint8(0x00 + 0x10))
UInt8

但在 Julia 0.4 中,您不必担心,因为它不再进行自动升级:

julia> typeof(0x00 + 0x10)
UInt8