I have found another useful application of types with value parameters in
C++. I have seen an example of using types to check for proper use of
physical units. I have found this very useful. But I haven't found a way to
express this in haskell. It would be nice to have a type system, that
supports that and similar applications.
Example (In C++, sorry):
// Here m, l, t anc stand for the exponent of mass, length, time and
current
template <int m, int l, int t, int c>
class physical {
explicit physical(double v);
...
};
template <int m, int l, int t, int c>
physical<m, l, t, c> operator + (
physical<m, l, t, c> v1, physical<m, l, t, c> v2
) {
...
}
template <int m1, int l1, int t1, int c1, int m2, int l2, int t2, int
c2>
physical<m1+m2, l1+l2, t1+t2, c1+c2> operator * (
physical<m1, l1, t1, c1> v1, physical<m2, l2, t2, c2> v2
) {
...
}
template <int m1, int l1, int t1, int c1, int m2, int l2, int t2, int
c2>
physical<m1-m2, l1-l2, t1-t2, c1-c2> operator / (
physical<m1, l1, t1, c1> v1, physical<m2, l2, t2, c2> v2
) {
...
}
typedef physical<0, 1, 0, 0> Distance;
typedef physical<0, 0, 1, 0> Time;
typedef physical<0, 1, 1, 0> Speed;
Speed s1 = Distance(100.0) / Time(5.0); // ok
Speed s1 = s2 + Time(4.0); // compile time error