If you think in terms of actual units, it is not a hack, it is what actually make sense. A dimensionless quantity does not assume dimensions, but it may be multiplied by a quantity with dimensions, and the result has the dimensions of that quantity.
It is not that you can “fix” the fact that you forgot to write the units of a quantity, because the types are different. For instance, you cannot do this:
julia> x = [ 1, 2 ];
julia> x[1] = 1u"km"
ERROR: DimensionError: and km are not dimensionally compatible.
Because x
is a container of unitless (Int64
) numbers only.
You can, however, do this:
julia> x = [1.0, 2.0]u"km"
2-element Vector{Quantity{Float64, 𝐋, Unitful.FreeUnits{(km,), 𝐋, nothing}}}:
1.0 km
2.0 km
julia> x[1] = 1.0u"m"
1.0 m
julia> x
2-element Vector{Quantity{Float64, 𝐋, Unitful.FreeUnits{(km,), 𝐋, nothing}}}:
0.001 km
2.0 km
since how it makes sense to convert the meter to the km unit which the vector carries.
*you could do this:
julia> x = Number[1.0, 2.0];
julia> x[1] = 1.0u"km"
1.0 km
julia> x
2-element Vector{Number}:
1.0 km
2.0
but that is only because that vector can contain anything that is a subtype of number, and there is no relation between the values before and after the mutation - and this is very bad for performance.