ianmackenzie / elm-units

Simple, safe and convenient unit types and conversions for Elm
https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/
BSD 3-Clause "New" or "Revised" License
85 stars 14 forks source link

Draft: Define module for Molarity, volume SI unit #42

Closed lenards closed 5 years ago

lenards commented 5 years ago

Relates to #6.

Offering this work, in draft form, to ensure I do not go too far.

I would also need to add the fuzzing tests for these 4 functions. And, consider defining "decimoles" in the Moles module.

Thank you in advance for your consideration and time.

I will expand the commit message per the guidance before making the PR finalized version.

ianmackenzie commented 5 years ago

Looks good so far! Reading through https://en.wikipedia.org/wiki/Molar_concentration and a few other pages it seems like moles per liter is the most common unit for molarity, so that should probably be included along with moles per cubic meter. I'm a bit less sure whether it should be called molesPerLiter (more explicit, works well in inverse form inMolesPerLiter) or molar (in common use, shorter).

I think for explicitness/consistency I'd be inclined to go with:

molesPerCubicMeter
inMolesPerCubicMeter
molesPerLiter
inMolesPerLiter
decimolesPerLiter
inDecimolesPerLiter
centimolesPerLiter
inCentimolesPerLiter
millimolesPerLiter
inMillimolesPerLiter
micromolesPerLiter
inMicromolesPerLiter

in the Molarity module and then add

decimoles
inDecimoles
centimoles
inCentimoles
millimoles
inMillimoles
micromoles
inMicromoles

to the SubstanceAmount module. Thoughts?

lenards commented 5 years ago

I'm good to add all definitions stated, if desired. Thank you for doing the background; and apologies for not offering a short summary on what I had read.

📝 millimoles and micromoles are provided in SubstanceAmount, I will confirm they're tested in the fuzzer list.

I'm adding a "To Do" at the end here that I can reference the final pull request.

Some thoughts

Is there is a guideline about naming when you have equivalence? I was using "Cubic Decimeters" because it was equivalent to Liters (Litres).

I believe that what is in the draft:

decimolesPerCubicDecimeter
inDecimolesPerCubicDecimeter

is the same as:

decimolesPerLiter
inDecimolesPerLiter

What I opted for I think it likely more cryptic. Though I'm curious if there just needs to be mention of this in the documentation for the module (which I still need to write).

Re molesPerLiter vs molar, from reading Chapter 8 of the NIST Guide on SI units, it seems like molar is more more general. Being out of a community that would come to the library with experience, I do not know that I have a good position to take. I don't know if we can take the question to the Elm discourse. Or offer molar as a delegated function definition that just called molesPerLiter.

To do

In SubstanceAmount module:

In Molarity module:

lenards commented 5 years ago

Closing this pull request. It has served the purpose of being a draft for feedback. It will be referenced in the final pull request.

🙇

ianmackenzie commented 5 years ago

Looking through that NIST reference (thanks for finding that!) I see "molar" being used as an adjective in several places (like "molar mass", which is something else entirely), but not as a unit. They even seem to suggest that the term "molarity" is obsolete, but only suggest "amount-of-substance concentration" as an alternative - and having a SubstanceAmountConcentration type and module just seems a little too verbose (even if it makes the relationship with SubstanceAmount pretty clear).

I don't have a strong rule for choosing between equivalent names - I really just do a bit of looking around at Wikipedia and similar sources and make a judgement call as to what seems most common (with, frankly, a certain amount of "what have I heard people use more often in my own experience"). I do think "liter" is pretty clearly more common than "cubic decimeter", though =)

I should have checked the SubstanceAmount module, thanks for pointing out that millimoles and micromoles are already there!

Finally, my inclination would be to just have molesPerLiter right now as it's more explicit than molar. If needed we can always add molar as an alias in the future, although it does seem a bit asymmetric; would the inverse function be inMolar? Seems weird.

Anyways, this is a long-winded way of saying that I agree with your to-do list =) I look forward to the final PR!

lenards commented 5 years ago

Excellent! :tada:

On Wed, Oct 9, 2019 at 2:37 PM Ian Mackenzie notifications@github.com wrote:

Looking through that NIST reference (thanks for finding that!) I see "molar" being used as an adjective in several places (like "molar mass", which is something else entirely), but not as a unit. They even seem to suggest that the term "molarity" is obsolete, but only suggest "amount-of-substance concentration" as an alternative - and having a SubstanceAmountConcentration type and module just seems a little too verbose (even if it makes the relationship with SubstanceAmount pretty clear).

I don't have a strong rule for choosing between equivalent names - I really just do a bit of looking around at Wikipedia and similar sources and make a judgement call as to what seems most common (with, frankly, a certain amount of "what have I heard people use more often in my own experience"). I do think "liter" is pretty clearly more common than "cubic decimeter", though =)

I should have checked the SubstanceAmount module, thanks for pointing out that millimoles and micromoles are already there!

Finally, my inclination would be to just have molesPerLiter right now as it's more explicit than molar. If needed we can always add molar as an alias in the future, although it does seem a bit asymmetric; would the inverse function be inMolar? Seems weird.

Anyways, this is a long-winded way of saying that I agree with your to-do list =) I look forward to the final PR!

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ianmackenzie/elm-units/pull/42?email_source=notifications&email_token=AAABOI2U22RNXJJ4YZXV62LQNZFKRA5CNFSM4I6YLHG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAZPU4Q#issuecomment-540211826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABOI3OHVNBPE2KVTR27M3QNZFKRANCNFSM4I6YLHGQ .