goldfirere / units

The home of the units Haskell package
94 stars 19 forks source link

Kinds of Quantities #66

Closed jerbaroo closed 2 years ago

jerbaroo commented 3 years ago

All the schemes described above, use a simplified representation of physical types, and do not incorporate ‘kind-of-quantity’ (KOQ), which is another attribute [7] of a physical type, at a higher abstraction than dimension. Thus, two quantities may have the same dimensions, but can be different kinds of quantities. Familiar examples are energy and torque, both of dimension ML2T-2, and heat capacity and entropy, both of dimension ML2T-2Θ-1.

https://www.researchgate.net/publication/326550053_Physical-type_correctness_in_scientific_Python

Is it possible with this units package to e.g. prevent addition of a value of type torque to a value of type energy?

goldfirere commented 3 years ago

Yes, but you'd have to do a little extra work to get there. The current implementation of SI dimensions does not include torque, but if it did, torque would be inter-convertible with energy. However, there is no reason you could not define a separate dimension (call it TorqueD) representing torque. This would be a new "base" dimension, not related to any other. Let's assume we have import qualified Data.Dimensions.DI as D. Then, you would then have functions toTorque :: MkQu_D (D.Length :* D.Force) -> MkQu_D TorqueD and fromTorque :: MkQu_D TorqueD -> MkQu_D (D.Length :* D.Force). These functions would internally be implemented using the unsafe Qu constructor from Data.Metrology.Unsafe, but (provided your representation of torque is consistent in your LCSU with your representation of length and force) they would actually be safe. With this setup, you would then be protected from adding your torque to your energy.

I hope this gives you enough to go on -- wasn't sure how much detail to include.

goldfirere commented 2 years ago

Hopefully my answer was sufficient -- closing.