Open fluffynukeit opened 10 years ago
I gave a first crack at this as a proof of concept in fluffynukeit/engineering-units@e81b9cb. I changed the terminology some to match NIST better. Specifically, length, time, etc are quantities; a numeric value is just a double; a value is a numeric value combined with units. I also had to use different operators than the ones I proposed originally because [
is reserved. I think the ones I picked are logical, but they contribute a lot to line noise because they are so similar to *
and /
, so there's still room for improvement.
This commit could use some additional polish in the doc and organization once it's decided whether these changes are desired.
Presently there is no type separation between quantities and units. This is something the dimensional package achieves with phantom types, and I think it would be useful in engineering-units.
For instance, the following are all valid expressions (including additions from PR #1 ).
I think the type system should prevent the "bad" usages listed above. I propose the following:
Prefixes then operate on units:
_c :: Value Unit -> Value Unit
Num
andFractional
instances forUnit
can be used to construct new units e.g.kg * m / s
Num
andFractional
instances forQuantity
can be used to do math:( 10 [ kg) * (2 [ m) / (3 [ s)
Quantity
types are created by tagging a numeric value with aUnit
using[
. I picked this function because it's similar to the notation NIST uses for units, and the notation I've seen used in academia: [m]. Really it could be almost anything else reasonable.One of the reasons I like the type separation between Units and Quantities is that units have value on their own. I'd like to use the units like this
data DataArray = DataArray Unit (Vector Double)
to associate an array of data with the units it is measured in.I can whip this up anytime if you like this direction. I'm going to test it out on my fork and reference the changes here when it's ready.