How would one go about modeling units (seconds, meters, meters per second, etc) in Haskell? I'm particularly interested in getting the typechecker to verify proper usage, and do not want to restrict it to any particular numeric representation (i.e. both integral seconds and fractional seconds). If this can in fact be done, it could also be used to model coordinate system axes in, say, Geometric Algebra.
- It can. Look at Dimensionalized numbers for a toy implementation. I've thought a bit about the Geometric Algebra case, but I can't see a good way of handling it without forcing a choice of basis. I'm also not sure how it would work -- the whole point of GA is to incorporate areas, lengths, volumes, etc. into one number type. I suppose we could use this type of technique to segregate GA spaces with different dimensions or even metrics. --AaronDenney
- I have implemented values equipped with physical units. Though all unit checking is made dynamically, that is expressions like
1 * meter < 2 * secondare accepted by the Haskell compiler but lead to a runtime error. -- HenningThielemann
darcs get http://darcs.haskell.org/numericprelude/