bjornbm / dimensional

Dimensional library variant built on Data Kinds, Closed Type Families, TypeNats (GHC 7.8+).
BSD 3-Clause "New" or "Revised" License
102 stars 16 forks source link

[question] How best to obtain numerical value from a dimensionless quantity? #187

Closed eriknstevenson closed 6 years ago

eriknstevenson commented 6 years ago

Hello,

First of all, thanks for the work you have put into this library, I have found it to be quite useful in my project. Just hoping to get some clarification on what is the best way to obtain a numerical value from a dimensionless quantity.

The documentation is clear for cases in which the value has a unit:

v :: Velocity Prelude.Double
v = 90 *~ (kilo meter / hour)
numval :: Prelude.Double
numval = v /~ (meter / second)

However, for cases such as the following:

v2 :: Velocity Prelude.Double
v2 = 150 *~ (kilo meter / hour)
vratio :: Dimensionless Double
vratio = v / v2

I am unsure of what unit to divide by here to obtain the double on its own.

I have currently resorted to the following:

numvratio :: Double
numvratio = (v /~ (kilo meter / hour)) Prelude./ (v2 /~ (kilo meter / hour))

Just wondering if there might be a nicer way to do this, and I apologize if I have missed something obvious in the documentation.

Thanks!

bjornbm commented 6 years ago

Hi Erik, just use the unit one! :)

On 5 May 2018, at 17:03, Erik Stevenson notifications@github.com wrote:

Hello,

First of all, thanks for the work you have put into this library, I have found it to be quite useful in my project. Just hoping to get some clarification on what is the best way to obtain a numerical value from a dimensionless quantity.

The documentation is clear for cases in which the value has a unit:

v :: Velocity Prelude.Double v = 90 *~ (kilo meter / hour) numval :: Prelude.Double numval = v /~ (meter / second) However, for cases such as the following:

v2 :: Velocity Prelude.Double v2 = 150 *~ (kilo meter / hour) vratio :: Dimensionless Double vratio = v / v2 I am unsure of what unit to divide by here to obtain the double on its own.

I have currently resorted to the following:

numvratio :: Double numvratio = (v /~ (kilo meter / hour)) Prelude./ (v2 /~ (kilo meter / hour)) Just wondering if there might be a nicer way to do this, and I apologize if I have missed something obvious in the documentation.

Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

eriknstevenson commented 6 years ago

Perfect! Thank you.

dmcclean commented 6 years ago

If you have suggestions as to how to improve the examples to make this more clear, they would be appreciated.