4 ms·
> physical quantities should [...] be encoded in the type system. But types are not just useful to specify the content of a variable, they are also useful to s
by bnegreve 5y ago
> physical quantities should [...] be encoded in the type system.
But types are not just useful to specify the content of a variable, they are also useful to specify the required precision.
So, if there is a type for seconds in the type system, should it be a 32 bits int or a 64 bits float? Only the user can say.
- valleyer 5y agoA generic type would be useful then: type DurationSeconds<Value> where Value: Numeric { ... } DurationSeconds<UInt32> DurationSeconds<Float64>
- account42 5y agoThis is exactly what C++ 11 did with std::chrono [0] except it goes one step further and makes the period generic too. [0] https://en.cppreference.com/w/cpp/chrono/duration https://en.cppreference.com/w/cpp/chrono/duration