I encountered a problem while working with the Units of Measurements functionality in metascala defined in the Units.scala file.
For the remainder of this question, I will use a simplified scheme with one type of Unit, length.
So, where the type actually looks like
Quantity[_1, _0, _0, _0, _0, _0, _0] ^ ^ ^ ^ ^ ^ ^ | | | | | | | | Mass | Crncy.| Mol | Length Time Temp. Lum.Intensity
this will be enough to demonstrate the problem:
Quantity[_1] ^ | Length
As soon as the type needs to be inferred, the problem begins.
Consider this example (also see UnitsTest.scala code):
val length: Quantity[_1] = m(5) val area: Quantity[_2] = length * length // (1) Works val dist: Quantity[_1] = area / length // (2) Doesn't work!
An error appears in the last line:
type mismatch; found : scalax.units.Units.Quantity[ scalax.units.Subtractables.-[ scalax.units.Integers._2, scalax.units.Integers._1 ] ] required: scalax.units.Units.Quantity[ scalax.units.Integers._1 ]
It seems that the compiler cannot understand that the type at hand is equal to Quantity[_1] , when the “extrusion dimension”, e. d. the transition from region to dist, as in (1) :
Quantity[_2 - _1] <<not equal to>> Quantity[_1]
The fallacy is that it works when “adding dimension” e. d. from length to region, as in (2) :
Quantity[_1 + _1] <<equal to>> Quantity[_2]
(Sorry for not inserting all the code here, this is too much. I tried to minimize my example, but I failed. That's why I just get in touch with it.)