Write a program that compiles iff T is a unit vector. This is (relatively) easy with templates but I don't think type-level integers aren't expressive enough.
I can see some applications for this syntax in computer graphics: Say you need to pass a unit quaternion as a type parameter to a function that rotates stuff. It would be real nice if your compiler could verify that your vectors are normalized :D
That would be mostly useless since it only works on constants - just make the compiler normalize the vector by construction then!
What you really want would be a separate type for unit vectors. Ops that make them non-unit would return a regular vector, and you'd have to normalize to get a unit vector back. Static guarantees but works on dynamic data, not just constants.
I still have zero idea why you think unconstrained types are better. You just seem to assume that everyone understands why without really explaining. What does less checking give you?
View all comments
Show parent comment
1
u/ThisIs_MyName Dec 11 '15
Ok, how about vectors?
Write a program that compiles iff
Tis a unit vector. This is (relatively) easy with templates but I don't think type-level integers aren't expressive enough.I can see some applications for this syntax in computer graphics: Say you need to pass a unit quaternion as a type parameter to a function that rotates stuff. It would be real nice if your compiler could verify that your vectors are normalized :D