Closed tebello-thejane closed 8 years ago
Thanks very much for the report, I'm very sorry about this issue.
It looks like what happened here is that when I was copying this example into the readme from a prior version of the project, I tried to clarify it and I didn't run my "clarifications" past the compiler.
The issue is that GravitationalParameter a
isn't the type of Newton's gravitational constant, G. It's instead the type of G times a mass. This is apparently commonly used in orbital mechanics (not my field) because the product can be measured with better precision than the two values alone. I evidently didn't know that when I made the change.
In the newly-released dimensional-codata
package we provide the following definition, which I recommend if you need to actually solve a problem similar to the one in the current example:
newtonianConstantOfGravitation :: (Fractional a) => Quantity ('Dim 'Pos3 'Neg1 'Neg2 'Zero 'Zero 'Zero 'Zero) a -- Pretty sure this dimension doesn't have a useful name.
newtonianConstantOfGravitation = 6.67408e-11 *~ (newton * (meter / kilo gram)^pos2)
Since copying that into the example would introduce either an additional dependency or an additional import (for Pos3
, Neg2
etc) and an additional language extension (DataKinds
) merely because we don't have a quantity synonym for the dimension of G, I'm inclined to rewrite the whole thing by picking a different example. I will try to get a minor release on hackage today with an example that works.
For your immediate use, the following version of the example code compiles and does what was intended:
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.NonSI (gee)
import Numeric.NumType.DK.Integers (TypeInt(..))
radiusOfEarth :: Length Double
radiusOfEarth = 6371 *~ kilo meter
massOfEarth :: Mass Double
massOfEarth = 5.97e24 *~ kilo gram
g :: Quantity ('Dim 'Pos3 'Neg1 'Neg2 'Zero 'Zero 'Zero 'Zero) Double
g = 6.67384e-11 *~ (newton * (meter / kilo gram)^pos2)
gravitationalFieldStrength :: Mass Double -> Length Double -> Acceleration Double
gravitationalFieldStrength m r = g * m / r^pos2
approximateAccelerationDueToGravityOnEarth :: Acceleration Double
approximateAccelerationDueToGravityOnEarth = gravitationalFieldStrength massOfEarth radiusOfEarth
differenceFromStandardValue :: Double
differenceFromStandardValue = approximateAccelerationDueToGravityOnEarth /~ gee
main = putStrLn . show $ differenceFromStandardValue
Hey.
No stress, man. I was just pointing out that the doc is incorrect, so that new users (such as myself) could use your amazing library better. Thanks for the quick response, and for alerting me to dimensional-codata
. :-D
Thanks again!
Fixed in 708a7dd3469663c62fd73b3ab1e5b67a9e34d095 and released to hackage as v1.0.1.1.
Excellent! Awesome, man. :-D :+1:
Let us know what else you find, or other areas where we can improve the documentation! Thanks again and happy holidays. :)
I get the following error when trying to compile the example in the
readme
, withmain = undefined
appended:Any ideas what's happening here? Perhaps GHC type inference is failing for
approximateAccelerationDueToGravityOnEarth
?