4 ms·
One practical use case is for dimensional analysis. A type is then a k-tuple of type-level integers where k is the number of primitive units, e.g. (kg, m, s).
by orlp 3y ago
One practical use case is for dimensional analysis. A type is then a k-tuple of type-level integers where k is the number of primitive units, e.g. (kg, m, s). Then m^2 / kg would be the tuple (-1, 2, 0). Multiplying two quantities adds the tuples elementwise. For example multiplying the above type by a quantity of type kg / m / s (corresponding to (1, -1, -1)) would give (0, 1 -1), which is the correct m / s.
Addition would only be allowed if the types are equal.
- ReleaseCandidat 3y agoThis doesn't work with dimensionless numbers, as they would need to have e.g. the type `(0, 0, 0)` for multiplication but `(-1, 2, 0)` or `(0, 1 -1)` for addition. Edit: I've just realised that that's actually correct ;)
- queuebert 3y agoThis could be fine, because in science we rarely add dimensionless numbers. Usually they are a scaling factor (i.e. multiplicative).