"Rainer Deyke" <[email protected]> wrote in message news:[email protected]... > bearophile wrote: >> Scala has a powerful type system that allows to implement such things >> in a good enough way: >> >> http://www.michaelnygard.com/blog/2009/05/units_of_measure_in_scala.html > > Either I'm missing something, or this system only checks units at > runtime (which would make it both slow and unsafe). > > Boost.Units (C++) checks units at compile time. There is no reason why > D could not use the same approach. >
I've been thinking it might be nice to have both. Compile-time for obvious reasons but then also run-time ones that could do conversions: double(inch) distance = 7; double(minute) time = 1.5; double(meter/second) velocity = distance / time; // Compile-time error auto velocity = convert(meter/second)(distance / time); // Actual runtime-conversion auto velocity = convert(meter)(distance / time); // Compile-time error: Incompatible Although that would probably be far from trivial to design/implement.
