-
Notifications
You must be signed in to change notification settings - Fork 17
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
Choose pattern for torsor newtypes #23
Comments
This is an interesting proposal, certainly worth thinking about. I've been inclined to stick to roughly the level of “support” corresponding to the NIST guide (which doesn't discuss torsors). But I could consider adding something like this if we get the API right. You can see how I have been treating absolute times (epochs) so far in https://github.com/bjornbm/astro/blob/master/Astro/Time.hs. Lines 110 to 130 correspond to the API in your “possible idea”. |
Lines 133 through 139 could be stolen as well, those are good operator names. But then again maybe having the one in dimensional would only help astro for interchange purposes on the concepts of time that are essentially classical. Because you also have a phantom type that represents the rate that time is advancing, if I understand it. Or sort of the place where the time is being measured. (Relativity loses me fairly quickly...) |
Might be best just to provide an instance for
The required
|
I'm a little bit reluctant to add a dependency (see also #30). Either way I think Torsors should go in their own module (Numeric.Units.Dimensional.Torsors), probably re-exported in the prelude once we are happy with the. You are welcome I draft a module if you want. |
Getting started in the experimental package: https://github.com/bjornbm/dimensional-dk-experimental/blob/master/Numeric/Units/Dimensional/DK/AbsoluteTemperature.hs |
It turns out that you can't do |
So the idea is to just use the |
I was thinking |
Hiding the constructor makes good sense as |
Do you have a feel for the relative merits of Conal's lib versus Ekmett's linear? (Except for number of dependencies.) |
No, none whatsoever. I will look into it though. |
linear's dependencies definitely seem to overlap better with my other needs.
Still not much of a clue about the merits. They seem very similar in this particular respect. |
Ok. Well feel free to switch if you prefer linear. |
vector-space defines a more general type for this kind of thing than linear does. Excerpting vector-space:
Matching definitions from linear:
(Note the superclass context on |
Question on this: |
Perhaps there are a lot more? Power, luminous intensity (etc), amount of substance, quantities that you get by dividing those by area/volume/time? |
Gravitational potential? Absolute rotation (and derived quantities such as angular momentum)? …
|
Temperatures and times present a few challenges. The
SIUnits
module deals with one of them by:I think this is not ideal because it encourages people to store absolute temperatures in
ThermodynamicTemperature a
form.Having
newtype AbsoluteTemperature a = AbsoluteTemperature (ThermodynamicTemperature a)
somewhere seems like a good idea from a documentation perspective, and also allows checking conversions between various absolute scales.Similar issues arise when tracking times, but they are even worse because the universe wasn't nice enough to supply us with an easily accessible "absolute". As a result, code with precision timekeeping needs generally requires not one but several newtypes for absolute times.
It would be nice if the core dimensional package addressed these concerns (at least the temperature one) to facilitate interoperability among other libraries developed on top of it.
I'm not sure if this can be addressed parametrically, or if it is better addressed by just laying down a pattern to be copied at each monomorphic concept where it is needed.
One possible idea (reserving comment on its merits):
Unfortunately this doesn't provide an opportunity for validation/canonicalization, so for example uses of
offset
can result in negativeAbsoluteTemperature
s. (Which, while it might make sense in itself, does not make sense as being offset from a nearby positive temperature, AFAIUI.) Typeclass pixie dust could remedy this defect, if it was thought to be worth it.(There is a related issue for angles, where there is a commonly needed newtype that treats
Angle a
values as equivalent when they are separated by an integer number of turns. Addressing that may or may not be done using similar techniques.)The text was updated successfully, but these errors were encountered: