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

Adds torque module #62

Closed gampleman closed 1 year ago

gampleman commented 1 year ago

Adding a log of some Slack conversations about some design decisions:

@gampleman I’m considering contributing a Torque module to elm-units, but wondering about the definition. The standard unit is the Newton-Metre, which one would normally write as type alias NewtonMeters = Product Newtons Meters. This is however identical to type alias Joules = Product Newtons Meters , so the compiler won’t complain if those quantities are ever confused (and they are different physics concepts). There seems to be some ideas of defining them as Ratio Joules Radians, which makes some sense, but might be confusing (and also unclear on how to call this unit).

@ianmackenzie My first reaction would be to just use 'Product Newton Meters' and accept the risk of confusing a torque value for a force one, but the ratio idea is interesting It would probably be useful to see what a few reasonable kinds of calculations would look like in each form Like obviously "compute a torque from a force and radius" is easier in one version and "compute energy from torque and angle" is easier in the other version, but what does it look like to do, say, each of those calculations using the 'wrong' representation That said I suspect a common use of torque would be with elm-physics and similar simulations, in which case I think the 'Product Newtons Meters' version would likely be a better fit Also some relevant discussion/thoughts in https://github.com/ianmackenzie/elm-units/issues/32

@gampleman At the moment we’re not really doing any calculations, we’re mostly using it as a way to not mix up our units. So I don’t have much perspective on this.

@ianmackenzie I think the most straightforward answer for now is to just use 'type alias NewtonMeters = Product Newtons Meters' and accept that that will be indistinguishable from Joules...in the long term I think it could indeed be good to take the approach discussed in https://github.com/ianmackenzie/elm-units/issues/32 and have every unit type be its own custom type by default, with explicit conversions to product/ratio form as needed

ianmackenzie commented 1 year ago

Looks good! My only request would be to add a torque section to Constants.elm with 'newtonMeter' and 'poundFoot' constants, then use the 'poundFoot' constant in Torque.elm

gampleman commented 1 year ago

OK, done.