null references redux + Looney Tunes

Nick Sabalausky a at a.a
Mon Oct 5 05:03:11 PDT 2009


"Rainer Deyke" <rainerd at eldwood.com> wrote in message 
news:haclah$33m$1 at digitalmars.com...
> 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.





More information about the Digitalmars-d mailing list