> Good idea. Andrew Kennedy wrote a whole thesis about this, and a
> paper or two besides.
>
> http://research.microsoft.com/~akenn/
Unfortunalty this work concentrates on extending a programming language
with units. It would be better to extend Haskell with more universal
features that makes the implementation of a library for units of measure
possible.
Using C++, one can define templates for proper handling of units without
additional language extensions:
template <int l, int t>
class Unit {
...
};
template <int l1, int t1, int l2, int t2>
Unit<l1+l2, t1+t2> operator * (Unit<l1, t1> value1, Unit<l2,t2>
value2) {
...
}
.. and so on ...
typedef Unit<1,0> Distance;
typedef Unit<0,1> Time;
typedef Unit<1,-1> Speed;
.. and so on ...
Here the template parameters l and t represent the exponents of length
and time.
The important thing here is that template classes can be parameterized
with values that can be enumerated (ints and enums) and not only with
types like in Haskell. Additionally it is possible to do computations
with these values at compile time.
Herbert