After several months of not-so-intensive work, I present the version 0.1 of the Units library: https://github.com/KarolS/units.
Units is a Scala library for providing type-level units of measurements checked on compile time. The goal of the library was to provide as seamless as possible way to check if the units used in arithmetic expressions are correct.
If you have tried to compile it: Yes it does compile that long. A clean build takes 100 seconds on my i7.
Compile-time unit checking has multiple applications:
-
scientists will be able to distinguish values in metres per second, metres, metres per second squared instead of crashing expensive space exploration equipment or drugging a patient
-
engineers will be able to distinguish values in metres, centimetres, feet, inches, litres, gallons instead of running out of fuel in the middle of a flight or thinking the distance to travel is many times shorter
-
designers will be able to distinguish values in millimetres, inches, pixels, points
-
economists will be able to distinguish values in euros, dollars, dollars per hour, ounces of gold
-
game developers will be able to distinguish values in pixels, tiles, damage points, minerals, barrels of vespen gas
-
network software developers will be able to distinguish values in kilobytes, kibibytes, kilobits, kilobits per second
-
and so on and on
There are not many languages with units of measurement support, the first that comes to mind is F#. I must admit that it is great at this. There also other languages that support units as a first-class language feature, and many that support units with a library. Those libraries vary in their expressibility and versatility, some of them only allow SI units, some of them require you to explicitly express relations between multiplied values, and some of them only support a limited subset of units. There have been earlier Scala libraries with units of measurements, but they all had severe limitations. Units library tries to be both expressive and versatile. While it’s not as powerful as F# built-in unit support, it definitely allows for quite a bit.
Enough of that, time for some examples that will showcase the main features.