iets3.opensource
iets3.opensource copied to clipboard
Physunits: Compatibility of units of the same quantity + conversions between them
Let's say the user writes: val length: number
As I understand it, units of the same quantity are always compatible, as there must be a conversion between them. At type system level, we only see 2x the quantity length here, so the types are compatible. We could add a checking rule that checks whether there really is an implicit conversion and otherwise displays an error. Implicit conversions (e.g. cm to m) can be currently intentionally deactivated. Otherwise, you can write things like assert 1 km equals 1000 [C] [1 ms], since 1km is automatically converted to 1000 m.
There is also the issue that after the conversion the value might not fit into a type when there is a range:
val length: number