Some of the methods defined in this package, such as the two-argument methods for the arithmetic functions, such as +, -, *, / have type signatures that are invalid because of being overly permissive. The issue is that ambiguity arises as soon as another package decides to do the same thing. Example:
julia> using DynamicQuantities
julia> q = 0.2u"m/s"
0.2 m s⁻¹
julia> struct Z <: Number end
julia> Base.:(*)(::Number, z::Z) = z
julia> q * Z()
ERROR: MethodError: *(::Quantity{Float64, Dimensions{FixedRational{Int32, 25200}}}, ::Z) is ambiguous.
Candidates:
*(l::AbstractQuantity, r::Number)
@ DynamicQuantities ~/tmp/jl/DynamicQuantities.jl/src/math.jl:19
*(::Number, z::Z)
@ Main REPL[4]:1
Possible fix, define
*(::AbstractQuantity, ::Z)
Stacktrace:
[1] top-level scope
@ REPL[5]:1
The solution is to set a more strict constraint for the "other type" in the type signature. Number is too permissive, as (some of) the quantity types defined here also subtype Number.
Some of the arithmetic methods defined in this package, those defined for AbstractGenericQuantity, do not constrain the "other type" at all!
Some of the methods defined in this package, such as the two-argument methods for the arithmetic functions, such as
+,-,*,/have type signatures that are invalid because of being overly permissive. The issue is that ambiguity arises as soon as another package decides to do the same thing. Example:The solution is to set a more strict constraint for the "other type" in the type signature.
Numberis too permissive, as (some of) the quantity types defined here also subtypeNumber.Some of the arithmetic methods defined in this package, those defined for
AbstractGenericQuantity, do not constrain the "other type" at all!