dimensional 1.0.1.0 → 1.0.1.1
raw patch · 5 files changed
+77/−23 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−4
- README.md +32/−13
- dimensional.cabal +4/−4
- examples/README +0/−2
- examples/ReadmeExample.hs +33/−0
CHANGELOG.md view
@@ -1,12 +1,16 @@+1.0.1.1 (2015-11) +----------------- +* Improved example in readme. + 1.0.1.0 (2015-11) ------------------- +----------------- * Added Numeric.Units.Dimensional.Coercion module. * Bumped exact-pi dependency to < 0.5. * Restored changelog. * Addressed issues with documentation. 1.0.0.0 (2015-11) ------------------- +----------------- * Changed to DataKinds and ClosedTypeFamilies encoding of dimensions. * Added names and exact values to `Unit`s. * Added `AnyUnit` and `AnyQuantity` for quantities whose dimension is statically unknown. @@ -70,14 +74,14 @@ 0.10.1 (2011-08) ------------------- +---------------- GHC 7.2.1 compatibility fix: * Increased CGS context-stack to 30. 0.10 (2011-05) -------------- +-------------- See the [announcement][2]. [2]: http://flygdynamikern.blogspot.se/2011/05/announce-dimensional-010.html
README.md view
@@ -5,7 +5,7 @@ Data kinds and closed type families provide a flexible, safe, and discoverable implementation that leads to largely self-documenting client code. -[](https://travis-ci.org/bjornbm/dimensional-dk) +[](https://travis-ci.org/bjornbm/dimensional) [](http://hackage.haskell.org/package/dimensional) ## Usage @@ -21,30 +21,49 @@ `Length Double` to mean `Quantity DLength Double`. A complete list of available aliases is given in the haddock documentation for the `Numeric.Units.Dimensional.Quantities`. +In the example below, we will solve a simple word problem. + +A car travels at 60 kilometers per hour for one mile, at 50 kph for one mile, +at 40 kph for one mile, and at 30 kph for one mile. How many minutes does the journey take? +What is the average speed of the car? How many seconds does the journey take, rounded up to the next whole second? + ```haskell {-# LANGUAGE NoImplicitPrelude #-} +module ReadmeExample where + import Numeric.Units.Dimensional.Prelude -import Numeric.Units.Dimensional.NonSI (gee) +import Numeric.Units.Dimensional.NonSI (mile) -radiusOfEarth :: Length Double -radiusOfEarth = 6371 *~ kilo meter +leg :: Length Double +leg = 1 *~ mile -- *~ combines a raw number and a unit to form a quantity -massOfEarth :: Mass Double -massOfEarth = 5.97e24 *~ kilo gram +speeds :: [Velocity Double] +speeds = [60, 50, 40, 30] *~~ (kilo meter / hour) + -- *~~ does the same thing for a whole Functor at once + -- Parentheses are required around unit expressions that are comingled with *~, /~, *~~, or /~~ operations -g :: GravitationalParameter Double -g = 6.67384e-11 *~ (meter^pos3 * (kilo gram)^neg1 * second^neg2) +timeOfJourney :: Time Double +timeOfJourney = sum $ fmap (leg /) speeds + -- We can use dimensional versions of ordinary functions like / and sum to combine quantities -gravitationalFieldStrength :: Mass a -> Length a -> Acceleration a -gravitationalFieldStrength m r = g * m / r^pos2 +averageSpeed :: Velocity Double +averageSpeed = _4 * leg / timeOfJourney + -- _4 is an alias for the dimensionless number 4 -approximateAccelerationDueToGravityOnEarth = gravitationalFieldStrength massOfEarth radiusOfEarth +wholeSeconds :: Integer +wholeSeconds = ceiling $ timeOfJourney /~ second + -- /~ lets us recover a raw number from a quantity and a unit in which it should be expressed -differenceFromStandardValue = approximateAccelerationDueToGravityOnEarth /~ gee +main :: IO () +main = do + putStrLn $ "Length of journey is: " ++ showIn minute timeOfJourney + putStrLn $ "Average speed is: " ++ showIn (mile / hour) averageSpeed + putStrLn $ "If we don't want to be explicit about units, the show instance uses the SI basis: " ++ show averageSpeed + putStrLn $ "The journey requires " ++ show wholeSeconds ++ " seconds, rounded up to the nearest second." ``` ## Contributing For project information (issues, updates, wiki, examples) see: - https://github.com/bjornbm/dimensional-dk + https://github.com/bjornbm/dimensional
dimensional.cabal view
@@ -1,12 +1,12 @@ name: dimensional -version: 1.0.1.0 +version: 1.0.1.1 license: BSD3 license-file: LICENSE copyright: Bjorn Buckwalter 2006-2015 author: Bjorn Buckwalter maintainer: bjorn@buckwalter.se stability: experimental -homepage: https://github.com/bjornbm/dimensional-dk/ +homepage: https://github.com/bjornbm/dimensional/ category: Math, Physics synopsis: Statically checked physical dimensions, using Type Families and Data Kinds. @@ -33,12 +33,12 @@ extra-source-files: README.md, CHANGELOG.md, - examples/README, + examples/ReadmeExample.hs, examples/GM.lhs source-repository head type: git - location: https://github.com/bjornbm/dimensional-dk/ + location: https://github.com/bjornbm/dimensional/ library build-depends: base >= 4.7 && < 5,
− examples/README
@@ -1,2 +0,0 @@-See the project wiki at http://dimensional.googlecode.com for more examples. -
+ examples/ReadmeExample.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE NoImplicitPrelude #-} + +module ReadmeExample where + +import Numeric.Units.Dimensional.Prelude +import Numeric.Units.Dimensional.NonSI (mile) + +leg :: Length Double +leg = 1 *~ mile -- *~ combines a raw number and a unit to form a quantity + +speeds :: [Velocity Double] +speeds = [60, 50, 40, 30] *~~ (kilo meter / hour) + -- *~~ does the same thing for a whole Functor at once + -- Parentheses are required around unit expressions that are comingled with *~, /~, *~~, or /~~ operations + +timeOfJourney :: Time Double +timeOfJourney = sum $ fmap (leg /) speeds + -- We can use dimensional versions of ordinary functions like / and sum to combine quantities + +averageSpeed :: Velocity Double +averageSpeed = _4 * leg / timeOfJourney + -- _4 is an alias for the dimensionless number 4 + +wholeSeconds :: Integer +wholeSeconds = ceiling $ timeOfJourney /~ second + -- /~ lets us recover a raw number from a quantity and a unit in which it should be expressed + +main :: IO () +main = do + putStrLn $ "Length of journey is: " ++ showIn minute timeOfJourney + putStrLn $ "Average speed is: " ++ showIn (mile / hour) averageSpeed + putStrLn $ "If we don't want to be explicit about units, the show instance uses the SI basis: " ++ show averageSpeed + putStrLn $ "The journey requires " ++ show wholeSeconds ++ " seconds, rounded up to the nearest second."