base unit SI unit symbol length L meter m mass M kilogram kg time T second s electric current I ampere A thermodynamic temperature Θ kelvin K amount of substance N mole mol luminous intensity J candela cd
is dimensional homogeneity. • Only commensurable quantities (physical quantities having the same dimension) may be compared, equated, added, or subtracted. • In other words, any physically meaningful equation will have the same dimensions on its left and right sides. • This can be used to spot errors in formulae or calculations.
• One may take ratios of incommensurable quantities (quantities with different dimensions), and multiply or divide them. • 1 + 2 is meaningless. • However, 1 ÷ 2 is fine.
a is a quantity which has int value 2 with dim L. • length is a phantom type. • It allows us to distinguish for each quantities. • Type params that are used only at compile time are called phantom types. quantity<length, int> a = 2;
expression, you will get a compile error. • A diagnostic message will then be displayed. // calc volume of a box quantity<volume, double> volume = x * y; // ^~~~~~~~~~~~~~~ ERROR! // compiler will show you diagnostic msg // (The message will be buried in a super long type name, but...)
Is coefficient in ℕ? A. YES if only for four arithmetic operations, but NO if you want to allow power roots. quantity<force, double> quantity<((M,1),(L,1),(T,-2)), double>
types • This allows for sanity checks at compile time • If the sanity check fails, a compile error occurs • Get long error messages • These error messages are like your life • And nobody loves you