-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One type to represent a Quantity with a given Unit? #110
Comments
Other possible names include |
I rather like
|
I agree that those are better. I'll throw
|
It now occurs to me based on the name |
Do we want to create a type that represents a
Quantity
represented in a specificUnit
?It's quite clear that having
Quantity
track only dimension and not unit is the correct design decision for uses ofQuantity
that involve actual computing and have actual physical meaning.It's less clear to me that we shouldn't also have a type pairing the two for use in user interfaces and perhaps in logs. For expository purposes let such a type be named
UQ :: Dimension -> * -> *
since I don't know what to call it yet.For example, the user input "3.7 feet" could usefully be parsed to a value of type
UQ DLength Scientific
before ultimately being converted to aLength Double
and passed to some physics code. This value would have the virtue of exactly preserving the data as given, which could be important e.g. for traceability.Similarly, on the output side, code that decides on display conventions for units and precision could convert a
Length Double
to aUQ DLength Scientific
before being passed to lower level code that converts it to aString
,Text
,JSON
, some HTML type, or whatever.I came to this idea because the UCUM grammar allows arbitrary decimal factors to appear in "units". We don't support that and probably don't want to. So perhaps our parser should return
AnyUQ ExactPi
instead ofAnyQuantity ExactPi
orAnyUnit
. This would preserve whatever information we have about how the value was given, but would also offer sensible encodings for these factors.At present I think that this is a great idea on two conditions:
The text was updated successfully, but these errors were encountered: