This is already implemented with manifold's unit expressions, but is made richer and more readable via concatenative features. For instance, '1.5 * USD' is not as readable as simply '1.5 USD'. However, unit expressions leverage operators for dimensional arithmetic:
Force f = 5 kg * 9.807 m/s/s; // result: 49.035 Newtons
Area space = (20ft + 2in) * (37ft + 7.5in); // result: 758 37/48 ft²
All unit expressions internally store amounts as SI units, which enables interunit expressions.
Length height = 6 ft + 4 cm; // mix SI and US units
out.println(height.to(ft)); // display any unit
You aren't limited to units. Generally, any concatenative sequence can be implemented. Like ranges:
IntegerRange range = 1 to 5;
Here the `to` identifier's type implements reactions to Number types to produce range types, which enables:
for (int i: 1 to 5) {
out.println(i);
}
See the manifold project's Unit and Science modules:
Force f = 5 kg * 9.807 m/s/s; // result: 49.035 Newtons
Area space = (20ft + 2in) * (37ft + 7.5in); // result: 758 37/48 ft²
All unit expressions internally store amounts as SI units, which enables interunit expressions.
Length height = 6 ft + 4 cm; // mix SI and US units
out.println(height.to(ft)); // display any unit
You aren't limited to units. Generally, any concatenative sequence can be implemented. Like ranges:
IntegerRange range = 1 to 5;
Here the `to` identifier's type implements reactions to Number types to produce range types, which enables:
for (int i: 1 to 5) { out.println(i); }
See the manifold project's Unit and Science modules:
Units: https://github.com/manifold-systems/manifold/tree/master/man...
Science: https://github.com/manifold-systems/manifold/tree/master/man...