# Operator-sensitive promotion¶

In certain cases, the simple rules for promotion may not be sufficient. For example, consider a type that can represent an object with physical units, here restricted to a single unit like “meter”:

immutable MeterUnits{T,P} <: Number
val::T
end
MeterUnits{T}(val::T, pow::Int) = MeterUnits{T,pow}(val)

m  = MeterUnits(1.0, 1)   # 1.0 meter, i.e. units of length
m2 = MeterUnits(1.0, 2)   # 1.0 meter^2, i.e. units of area

Now let’s define the operations + and * for these objects: m+m should have the type of m but m*m should have the type of m2. When the result type depends on the operation, and not just the input types, promote_rule will be inadequate.

Fortunately, it’s possible to provide such definitions via promote_op: