packages feed

dimensional 1.1 → 1.6.2

raw patch · 21 files changed

Files

CHANGELOG.md view
@@ -1,3 +1,47 @@+1.6.2 (2026-01)+---------------++* Support for GHC 9.14;++1.6.1 (2024-10)+---------------++* Fixed an issue where `Control.DeepSeq.Unit`, exported as of version 1.5.1.0, conflicts with `Numeric.Units.Dimensional.Unit` (#228).+* Fixed broken links to the Tau and Pi manifestos (#229).++1.6 (2024-08)+-------------++* Added a package flag `binary`, enabling optional dependency on the `binary` package to provide instances of `Binary`.++1.5 (2022-06)+-------------+* Add Julian `decade` and `millennium` to `NonSI`.+* Rename `deka` prefix to `deca` in accordance with [international spelling](https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf/fcf090b2-04e6-88cc-1149-c3e029ad8232).+* Change `astronomicalUnit` symbol to lowercase (`au`).+* Remove `semigroups` dependency.+* Significant documentation improvements.++Thanks to @konsumlamm for many contributions!+++1.4 (2021-05)+-------------+* Add `calorie` to `NonSI`.+* Remove deprecated `AutoDeriveTypeable` pragmas. This means that `Typable` instances are no provided on GHC prior to 8.2.++1.3 (2018-12)+-------------+* Breaking: Changed the `Show` instances for `UnitName`, `Unit`, `SQuantity` to use non-breaking spaces+  within unit names and between values and their units.+* Bumped exact-pi dependency to < 0.6.+* Added the dimensionless unit `percent`.+* Added dimensionless wrappers for `log1p`, `expm1`, `log1pexp`, and `log1mexp` from the `Floating` class.++1.2 (2018-11)+-------------+* Add `NoStarIsType` extension and import `Data.Kind.Type` for [GHC 8.6 compitbility](https://github.com/ghc-proposals/ghc-proposals/blob/05721788de9ab6538def68c3c2c9dec50c9f24a8/proposals/0020-no-type-in-type.rst). Abandon compatibility with GHC < 8.+ 1.1 (2018-03) ------------- * Added `Semigroup` instances for [GHC 8.4 compatibility](https://ghc.haskell.org/trac/ghc/wiki/Migration/8.4#SemigroupMonoidsuperclasses).@@ -118,7 +162,7 @@ *  Added [`tau`][3]. *  Added `KinematicViscosity`. -[3]: http://tauday.com/tau-manifesto+[3]: https://tauday.com/tau-manifesto   0.10.1.2 (2011-09)@@ -142,11 +186,11 @@ -------------- See the [announcement][2]. -[2]: http://flygdynamikern.blogspot.se/2011/05/announce-dimensional-010.html+[2]: https://flygdynamikern.blogspot.se/2011/05/announce-dimensional-010.html   0.9 (2011-04) ------------- See the [announcement][1]. -[1]: http://flygdynamikern.blogspot.se/2011/04/announce-dimensional-09.html+[1]: https://flygdynamikern.blogspot.se/2011/04/announce-dimensional-09.html
README.md view
@@ -5,8 +5,7 @@ Data kinds and closed type families provide a flexible, safe, and discoverable implementation that leads to largely self-documenting client code. -[![Build Status](https://travis-ci.org/bjornbm/dimensional.svg?branch=master)](https://travis-ci.org/bjornbm/dimensional)-[![Hackage Version](http://img.shields.io/hackage/v/dimensional.svg)](http://hackage.haskell.org/package/dimensional)+[![Hackage Version](https://img.shields.io/hackage/v/dimensional.svg)](https://hackage.haskell.org/package/dimensional) [![Stackage version](https://www.stackage.org/package/dimensional/badge/lts?label=Stackage)](https://www.stackage.org/package/dimensional)  ## Usage@@ -62,6 +61,21 @@          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."+```++## Package Flags++To provide `Binary` serialization for `Quantity` from the `binary` package, the `binary` flag can be used like so:++```bash+cabal install dimensional -f binary+```++If you use a `cabal.project` file, you can instead add the following clause to activate this package flag:++```txt+package dimensional+    flags: +binary ```  ## Contributing
dimensional.cabal view
@@ -1,18 +1,25 @@ name:                dimensional-version:             1.1+version:             1.6.2 license:             BSD3 license-file:        LICENSE-copyright:           Bjorn Buckwalter 2006-2018+copyright:           Bjorn Buckwalter 2006-2024 author:              Bjorn Buckwalter maintainer:          bjorn@buckwalter.se stability:           experimental homepage:            https://github.com/bjornbm/dimensional/ bug-reports:         https://github.com/bjornbm/dimensional/issues/ category:            Math, Physics-synopsis:            Statically checked physical dimensions,-                     using Type Families and Data Kinds.+synopsis:            Statically checked physical dimensions cabal-version:       >= 1.10-tested-with:         GHC == 7.8.4, GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3, GHC == 8.0.1, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1+tested-with:         GHC == 8.10.7,+                     GHC == 9.0.2,+                     GHC == 9.2.8,+                     GHC == 9.4.8,+                     GHC == 9.6.7,+                     GHC == 9.8.4,+                     GHC == 9.10.3,+                     GHC == 9.12.2,+                     GHC == 9.14.1 build-type:          Simple  description:@@ -21,7 +28,7 @@     with physical quantities and units. Information about the physical     dimensions of the quantities and units is embedded in their types and the     validity of operations is verified by the type checker at compile time.-    The boxing and unboxing of numerical values as quantities is done by+    The wrapping and unwrapping of numerical values as quantities is done by     multiplication and division with units. The library is designed to, as     far as is practical, enforce/encourage best practices of unit usage. @@ -30,47 +37,57 @@     rather than functional dependencies. This enables a number of features, including     improved support for unit names and quantities with statically-unknown dimensions. -    Requires GHC 7.8 or later.+    Requires GHC 8.0 or later.  extra-source-files:  README.md,                      CHANGELOG.md,                      examples/ReadmeExample.hs,-                     examples/GM.lhs+                     examples/GM.lhs,+                     examples/NewtonianMechanics.hs +flag binary+  description: Provide instances for use with the binary package.+  default:     False+  manual:      True+ source-repository head   type:     git   location: https://github.com/bjornbm/dimensional/  library-  build-depends:       base >= 4.7 && < 5,+  build-depends:       base >= 4.9 && < 5,                        deepseq >= 1.3,-                       exact-pi >= 0.4.1 && < 0.5,+                       exact-pi >= 0.4.1 && < 0.6,                        ieee754 >= 0.7.6,                        numtype-dk >= 0.5 && < 1.1,-                       vector >= 0.10,-                       semigroups+                       vector >= 0.10   hs-source-dirs:      src   default-language:    Haskell2010   default-extensions:  NoImplicitPrelude+  if impl(ghc >= 8.6)+    default-extensions: NoStarIsType   ghc-options:         -Wall-  exposed-modules:     Numeric.Units.Dimensional,-                       Numeric.Units.Dimensional.Coercion,-                       Numeric.Units.Dimensional.Dimensions,-                       Numeric.Units.Dimensional.Dimensions.TermLevel,-                       Numeric.Units.Dimensional.Dimensions.TypeLevel,-                       Numeric.Units.Dimensional.Dynamic,-                       Numeric.Units.Dimensional.FixedPoint,-                       Numeric.Units.Dimensional.Functor,-                       Numeric.Units.Dimensional.NonSI,-                       Numeric.Units.Dimensional.Prelude,-                       Numeric.Units.Dimensional.Quantities,-                       Numeric.Units.Dimensional.SIUnits,-                       Numeric.Units.Dimensional.UnitNames,-                       Numeric.Units.Dimensional.UnitNames.InterchangeNames,-                       Numeric.Units.Dimensional.Variants,+  exposed-modules:     Numeric.Units.Dimensional+                       Numeric.Units.Dimensional.Coercion+                       Numeric.Units.Dimensional.Dimensions+                       Numeric.Units.Dimensional.Dimensions.TermLevel+                       Numeric.Units.Dimensional.Dimensions.TypeLevel+                       Numeric.Units.Dimensional.Dynamic+                       Numeric.Units.Dimensional.FixedPoint+                       Numeric.Units.Dimensional.Functor+                       Numeric.Units.Dimensional.NonSI+                       Numeric.Units.Dimensional.Prelude+                       Numeric.Units.Dimensional.Quantities+                       Numeric.Units.Dimensional.SIUnits+                       Numeric.Units.Dimensional.UnitNames+                       Numeric.Units.Dimensional.UnitNames.InterchangeNames+                       Numeric.Units.Dimensional.Variants                        Numeric.Units.Dimensional.Float-  other-modules:       Numeric.Units.Dimensional.Internal,+  other-modules:       Numeric.Units.Dimensional.Internal                        Numeric.Units.Dimensional.UnitNames.Internal+  if flag(binary)+    build-depends:     binary >= 0.7 && < 1+    cpp-options:       -DUSE_BINARY  test-suite tests   type:                exitcode-stdio-1.0@@ -78,6 +95,8 @@   hs-source-dirs:      tests   default-language:    Haskell2010   default-extensions:  NoImplicitPrelude+  if impl(ghc >= 8.6)+    default-extensions: NoStarIsType   other-modules:       Numeric.Units.DimensionalSpec                        Numeric.Units.Dimensional.DynamicSpec                        Numeric.Units.Dimensional.QuantitiesSpec@@ -86,19 +105,7 @@                        hspec,                        QuickCheck,                        base--test-suite doctests-  type:                exitcode-stdio-1.0-  ghc-options:         -threaded-  main-is:             DocTests.hs-  hs-source-dirs:      tests-  default-language:    Haskell2010-  build-depends:       dimensional,-                       doctest,-                       Glob,-                       QuickCheck,-                       template-haskell,-                       base+  build-tool-depends: hspec-discover:hspec-discover == 2.*  benchmark simple   type:                exitcode-stdio-1.0
+ examples/NewtonianMechanics.hs view
@@ -0,0 +1,37 @@+{-# LANGUAGE NoImplicitPrelude #-}+module NewtonianMechanics where++import Numeric.Units.Dimensional.Prelude++translationalKineticEnergy :: (Fractional a) => Mass a -> Velocity a -> Energy a+translationalKineticEnergy m v = m * v ^ pos2 / _2++translationalWork :: (Num a) => Force a -> Length a -> Energy a+translationalWork f d = f * d++translationalMomentum :: (Num a) => Mass a -> Velocity a -> Momentum a+translationalMomentum m v = m * v++translationalPower :: (Num a) => Force a -> Velocity a -> Power a+translationalPower f v = f * v++forceFromChangeInMomentum :: (Fractional a) => Momentum a -> Time a -> Force a+forceFromChangeInMomentum dp dt = dp / dt++rotationalKineticEnergy :: (Fractional a) => MomentOfInertia a -> AngularVelocity a -> Energy a+rotationalKineticEnergy i w = i * w ^ pos2 / _2++rotationalWork :: (Num a) => Torque a -> PlaneAngle a -> Energy a+rotationalWork t th = t * th++rotationalMomentum :: (Num a) => MomentOfInertia a -> AngularVelocity a -> AngularMomentum a+rotationalMomentum i w = i * w++rotationalPower :: (Num a) => Torque a -> AngularVelocity a -> Power a+rotationalPower t w = t * w++torque :: (Num a) => Force a -> Length a -> Torque a+torque r f = r * f++torqueFromChangeInMomentum :: (Fractional a) => AngularMomentum a -> Time a -> Torque a+torqueFromChangeInMomentum dL dt = dL / dt
src/Numeric/Units/Dimensional.hs view
@@ -1,8 +1,6 @@ {-# OPTIONS_HADDOCK show-extensions #-} -{-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}@@ -33,7 +31,7 @@ physical quantities and units. Information about the physical dimensions of the quantities/units is embedded in their types and the validity of operations is verified by the type checker at compile-time. The boxing and unboxing of numerical values as quantities is+time. The wrapping and unwrapping of numerical values as quantities is done by multiplication and division of units, of which an incomplete set is provided. @@ -49,7 +47,7 @@ == Disclaimer  Merely an engineer, the author doubtlessly uses a language and-notation that makes mathematicians and physicist cringe. He does+notation that makes mathematicians and physicists cringe. He does not mind constructive criticism (or pull requests).  The sets of functions and units defined herein are incomplete and@@ -59,11 +57,11 @@  == Preliminaries -This module requires GHC 7.8 or later. We utilize Data Kinds, TypeNats,+This module requires GHC 8 or later. We utilize Data Kinds, TypeNats, Closed Type Families, etc. Clients of the module are generally not required to use these extensions. -Clients probably will want to use the NegativeLiterals extension.+Clients probably will want to use the @NegativeLiterals@ extension though.  == Examples @@ -71,23 +69,23 @@ work with physical quantities. A physical quantity is defined by multiplying a number with a unit (the type signature is optional). -> v :: Velocity Prelude.Double+> v :: Velocity Double > v = 90 *~ (kilo meter / hour)  It follows naturally that the numerical value of a quantity is obtained by division by a unit. -> numval :: Prelude.Double+> numval :: Double > numval = v /~ (meter / second)  The notion of a quantity as the product of a numerical value and a unit is supported by 7.1 "Value and numerical value of a quantity" of-<#note1 [1]>. While the above syntax is fairly natural it is unfortunate that+<#note1 [1]>. While the above syntax is fairly natural, it is unfortunate that it must violate a number of the guidelines in <#note1 [1]>, in particular 9.3 "Spelling unit names with prefixes", 9.4 "Spelling unit names obtained by multiplication", 9.5 "Spelling unit names obtained by division". -As a more elaborate example of how to use the module we define a+As a more elaborate example of how to use the module, we define a function for calculating the escape velocity of a celestial body <#note2 [2]>. @@ -97,9 +95,9 @@ >       two = 2 *~ one >       g = 6.6720e-11 *~ (newton * meter ^ pos2 / kilo gram ^ pos2) -For completeness we should also show an example of the error messages+For completeness, we should also show an example of the error messages we will get from GHC when performing invalid arithmetic. In the-best case GHC will be able to use the type synonyms we have defined+best case, GHC will be able to use the type synonyms we have defined in its error messages.  > let x = 1 *~ meter + 1 *~ second@@ -111,7 +109,7 @@ > In the second argument of `(*~)', namely `second' > In the second argument of `(+)', namely `1 *~ second' -In other cases the error messages aren't very friendly.+In other cases, the error messages aren't very friendly.  > let x = 1 *~ meter / (1 *~ second) + 1 *~ kilo gram >@@ -141,7 +139,7 @@  == Related work -Henning Thielemann numeric prelude has a physical units library,+Henning Thielemann's numeric prelude has a physical units library, however, checking of dimensions is dynamic rather than static. Aaron Denney has created a toy example of statically checked physical dimensions covering only length and time. HaskellWiki@@ -157,13 +155,13 @@  == References -1. #note1# http://physics.nist.gov/Pubs/SP811/-2. #note2# http://en.wikipedia.org/wiki/Escape_velocity-3. #note3# http://jscience.org/api/org/jscience/physics/models/package-summary.html-4. #note4# http://www.haskell.org/haskellwiki/Physical_units-5. #note5# http://liftm.wordpress.com/2007/06/03/scientificdimension-type-arithmetic-and-physical-units-in-haskell/+1. #note1# https://www.nist.gov/pml/special-publication-811+2. #note2# https://en.wikipedia.org/wiki/Escape_velocity+3. #note3# https://web.archive.org/web/20080905151927/http://jscience.org/api/org/jscience/physics/models/package-summary.html+4. #note4# https://wiki.haskell.org/Physical_units+5. #note5# https://liftm.wordpress.com/2007/06/03/scientificdimension-type-arithmetic-and-physical-units-in-haskell/ 6. #note6# http://jscience.org/-7. #note7# http://research.sun.com/projects/plrg/fortress.pdf+6. #note6# https://github.com/stokito/fortress-lang  -} @@ -188,7 +186,7 @@     (^), (^/), (**), (*), (/), (+), (-),     negate, abs, signum, recip, nroot, sqrt, cbrt,     -- ** Transcendental Functions-    exp, log, logBase, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, atan2,+    exp, log, logBase, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, atan2, log1p, expm1, log1pexp, log1mexp,     -- ** Operations on Collections     -- $collections     (*~~), (/~~), sum, mean, product, dimensionlessLength, nFromTo,@@ -228,9 +226,10 @@   ) import Data.Data import Data.ExactPi-import Data.Foldable (Foldable(foldr))+import Data.Foldable (Foldable(foldr, length)) import Data.Maybe import Data.Ratio+import qualified Numeric import Numeric.Units.Dimensional.Dimensions import Numeric.Units.Dimensional.Internal import Numeric.Units.Dimensional.UnitNames hiding ((*), (/), (^), weaken, strengthen, product)@@ -238,21 +237,11 @@ import Numeric.Units.Dimensional.Variants hiding (type (*), type (/)) import qualified Numeric.Units.Dimensional.Variants as V --- Provide a version of length which is compatible with base-4.8's version.--- Where 4.8 is available we use that version as it may have performance advantages.--- Where it is not available we implement it in terms of foldl'.-#if MIN_VERSION_base(4,8,0)-import Data.Foldable (Foldable(length))-#else-import Data.Foldable (Foldable(foldl'))--length :: Foldable t => t a -> Int-length = foldl' (\c _ -> c Prelude.+ 1) 0-#endif- -- $setup -- >>> :set -XFlexibleInstances -- >>> :set -XNoImplicitPrelude+-- >>> :set -fno-warn-orphans+-- >>> :set -fno-warn-type-defaults -- >>> import Test.QuickCheck.Arbitrary -- >>> import Numeric.Units.Dimensional.Prelude -- >>> import Numeric.Units.Dimensional.Float@@ -329,12 +318,12 @@ infixl 7  *~, /~  {- $dimensions-The phantom type variable d encompasses the physical dimension of-a 'Dimensional'. As detailed in <#note5 [5]> there are seven base dimensions,+The phantom type variable @d@ encompasses the physical dimension of+a 'Dimensional'. As detailed in <#note5 [5]>, there are seven base dimensions, which can be combined in integer powers to a given physical dimension. We represent physical dimensions as the powers of the seven base dimensions that make up the given dimension. The powers are represented-using NumTypes. For convenience we collect all seven base dimensions+using NumTypes. For convenience, we collect all seven base dimensions in a data kind 'Dimension'.  We could have chosen to provide type variables for the seven base@@ -370,7 +359,7 @@ type LuminousIntensity        = Quantity DLuminousIntensity  {- $dimension-arithmetic-When performing arithmetic on units and quantities the arithmetics+When performing arithmetic on units and quantities, the arithmetics must be applied to both the numerical values of the Dimensionals but also to their physical dimensions. The type level arithmetic on physical dimensions is governed by closed type families expressed@@ -404,14 +393,14 @@ -- | Divides one 'Quantity' by another or one 'Unit' by another. -- -- The intimidating type signature captures the similarity between these operations--- and ensures that composite 'Unit's are 'NotPrefixable'.+-- and ensures that composite 'Unit's are 'NonMetric'. (/) :: (KnownVariant v1, KnownVariant v2, KnownVariant (v1 V./ v2), Fractional a) => Dimensional v1 d1 a -> Dimensional v2 d2 a -> Dimensional (v1 V./ v2) (d1 / d2) a (/) = liftD2 (Prelude./) (Prelude./) (Name./)  -- | Forms the reciprocal of a 'Quantity', which has the reciprocal dimension. -- -- >>> recip $ 47 *~ hertz--- 2.127659574468085e-2 s+-- 2.127659574468085e-2 s recip :: (Fractional a) => Quantity d a -> Quantity (Recip d) a recip = liftQ Prelude.recip @@ -423,7 +412,7 @@ -- also reexported by "Numeric.Units.Dimensional.Prelude". -- -- The intimidating type signature captures the similarity between these operations--- and ensures that composite 'Unit's are 'NotPrefixable'.+-- and ensures that composite 'Unit's are 'NonMetric'. (^) :: (Fractional a, KnownTypeInt i, KnownVariant v, KnownVariant (Weaken v))     => Dimensional v d1 a -> Proxy i -> Dimensional (Weaken v) (d1 ^ i) a x ^ n = let n' = (toNum n) :: Int@@ -530,7 +519,7 @@ (^/) = flip nroot  {- $collections-Here we define operators and functions to make working with homogenuous+Here we define operators and functions to make working with homogeneous lists of dimensionals more convenient.  We define two convenience operators for applying units to all@@ -550,10 +539,10 @@ -- | The sum of all elements in a foldable structure. -- -- >>> sum ([] :: [Mass Double])--- 0.0 kg+-- 0.0 kg -- -- >>> sum [12.4 *~ meter, 1 *~ foot]--- 12.7048 m+-- 12.7048 m sum :: (Num a, Foldable f) => f (Quantity d a) -> Quantity d a sum = foldr (+) _0 @@ -612,7 +601,7 @@ that may be obviously useful. -} -exp, log, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh+exp, log, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, log1p, expm1, log1pexp, log1mexp   :: Floating a => Dimensionless a -> Dimensionless a exp   = fmap Prelude.exp log   = fmap Prelude.log@@ -628,6 +617,10 @@ asinh = fmap Prelude.asinh acosh = fmap Prelude.acosh atanh = fmap Prelude.atanh+log1p = fmap Numeric.log1p+expm1 = fmap Numeric.expm1+log1pexp = fmap Numeric.log1pexp+log1mexp = fmap Numeric.log1mexp  -- | Raises a dimensionless quantity to a dimensionless power. (**) :: Floating a => Dimensionless a -> Dimensionless a -> Dimensionless a@@ -664,9 +657,9 @@ -- | The unit 'one' has dimension 'DOne' and is the base unit of dimensionless values. -- -- As detailed in 7.10 "Values of quantities expressed simply as numbers:--- the unit one, symbol 1" of <#note1 [1]> the unit one generally does not+-- the unit one, symbol 1" of <#note1 [1]>, the unit one generally does not -- appear in expressions. However, for us it is necessary to use 'one'--- as we would any other unit to perform the "boxing" of dimensionless values.+-- as we would any other unit to perform the "wrapping" of dimensionless values. one :: Num a => Unit 'NonMetric DOne a one = Unit nOne 1 1 @@ -699,8 +692,8 @@  -- | Twice 'pi'. ----- For background on 'tau' see http://tauday.com/tau-manifesto (but also--- feel free to review http://www.thepimanifesto.com).+-- For background on 'tau' see https://tauday.com/tau-manifesto (but also+-- feel free to review https://web.archive.org/web/20200926221249/http://www.thepimanifesto.com/). tau :: Floating a => Dimensionless a tau = _2 * pi @@ -716,7 +709,7 @@ -- -- >>> let x = (37 :: Rational) *~ poundMass -- >>> changeRep x :: Mass Double--- 16.78291769 kg+-- 16.78291769 kg changeRep :: (KnownVariant v, Real a, Fractional b) => Dimensional v d a -> Dimensional v d b changeRep = dmap realToFrac 
src/Numeric/Units/Dimensional/Dimensions/TermLevel.hs view
@@ -1,6 +1,7 @@ {-# OPTIONS_HADDOCK not-home, show-extensions #-}  {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}@@ -35,7 +36,10 @@ ) where -import Control.DeepSeq+import Control.DeepSeq (NFData(..))+#if USE_BINARY+import qualified Data.Binary+#endif import Data.Data import Data.Semigroup (Semigroup(..)) import Data.Monoid (Monoid(..))@@ -44,6 +48,7 @@ import qualified Prelude as P  -- $setup+-- >>> :set -fno-warn-orphans -- >>> import Prelude (negate) -- >>> import Control.Applicative -- >>> import Test.QuickCheck.Arbitrary@@ -64,8 +69,12 @@ -- | The monoid of dimensions under multiplication. instance Monoid Dimension' where   mempty = dOne-  mappend = (Data.Semigroup.<>)+  mappend = (<>) +#if USE_BINARY+instance Data.Binary.Binary Dimension'+#endif+ -- | The dimension of a dynamic value, which may not have any dimension at all. data DynamicDimension = NoDimension -- ^ The value has no valid dimension.                       | SomeDimension Dimension' -- ^ The value has the given dimension.@@ -74,10 +83,14 @@  instance NFData DynamicDimension where +#if USE_BINARY+instance Data.Binary.Binary DynamicDimension+#endif+ -- | Dimensional values, or those that are only possibly dimensional, inhabit this class, -- which allows access to a term-level representation of their dimension. class HasDynamicDimension a where-  -- | Gets the 'DynamicDimension of a dynamic dimensional value, which may be 'NoDimension' if it does not represent+  -- | Gets the 'DynamicDimension' of a dynamic dimensional value, which may be 'NoDimension' if it does not represent   -- a dimensional value of any 'Dimension'.   --   -- A default implementation is available for types that are also in the `HasDimension` typeclass.@@ -187,6 +200,9 @@ asList :: Dimension' -> [Int] asList (Dim' l m t i th n j) = [l, m, t, i, th, n, j] +-- | Converts a list of integers, representing the exponent associated with each+-- of the 7 SI base dimensions in the standard order, to a dimension.+-- Returns 'Nothing' if the list doesn't contain exactly 7 elements. fromList :: [Int] -> Maybe Dimension' fromList [l, m, t, i, th, n, j] = Just $ Dim' l m t i th n j fromList _ = Nothing
src/Numeric/Units/Dimensional/Dimensions/TypeLevel.hs view
@@ -78,9 +78,9 @@ infixr 8  ^ infixl 7  *, / --- | Multiplication of dimensions corresponds to adding of the base+-- | Multiplication of dimensions corresponds to addition of the base -- dimensions' exponents.-type family (a::Dimension) * (b::Dimension) where+type family (a :: Dimension) * (b :: Dimension) where   DOne * d = d   d * DOne = d   ('Dim l  m  t  i  th  n  j) * ('Dim l' m' t' i' th' n' j')@@ -88,7 +88,7 @@  -- | Division of dimensions corresponds to subtraction of the base -- dimensions' exponents.-type family (a::Dimension) / (d::Dimension) where+type family (a :: Dimension) / (d :: Dimension) where   d / DOne = d   d / d = DOne   ('Dim l  m  t  i  th  n  j) / ('Dim l' m' t' i' th' n' j')@@ -98,21 +98,21 @@ -- or of negating each of the base dimensions' exponents. type Recip (d :: Dimension) = DOne / d --- | Powers of dimensions corresponds to multiplication of the base+-- | Powers of dimensions correspond to multiplication of the base -- dimensions' exponents by the exponent. -- -- We limit ourselves to integer powers of Dimensionals as fractional -- powers make little physical sense.-type family (d::Dimension) ^ (x::TypeInt) where+type family (d :: Dimension) ^ (x :: TypeInt) where   DOne ^ x = DOne   d ^ 'Zero = DOne   d ^ 'Pos1 = d   ('Dim l  m  t  i  th  n  j) ^ x     = 'Dim (l N.* x) (m N.* x) (t N.* x) (i N.* x) (th N.* x) (n N.* x) (j N.* x) --- | Roots of dimensions corresponds to division of the base dimensions'+-- | Roots of dimensions correspond to division of the base dimensions' -- exponents by the order of the root.-type family NRoot (d::Dimension) (x::TypeInt) where+type family NRoot (d :: Dimension) (x :: TypeInt) where   NRoot DOne x = DOne   NRoot d 'Pos1 = d   NRoot ('Dim l  m  t  i  th  n  j) x@@ -128,7 +128,7 @@ -- Each validly constructed type of kind 'Dimension' has a 'KnownDimension' instance. -- -- While 'KnownDimension' is a constraint synonym, the presence of @'KnownDimension' d@ in---  a context allows use of @'dimension' :: 'Proxy' d -> 'Dimension''@.+-- a context allows use of @'dimension' :: 'Proxy' d -> 'Dimension''@. type KnownDimension (d :: Dimension) = HasDimension (Proxy d)  instance ( KnownTypeInt l
src/Numeric/Units/Dimensional/Dynamic.hs view
@@ -9,6 +9,7 @@ Defines types for manipulation of units and quantities without phantom types for their dimensions. -} +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}@@ -35,10 +36,14 @@ , (*), (/), (^), recip, applyPrefix ) where -import Control.DeepSeq+import Control.DeepSeq (NFData) import Control.Monad+#if USE_BINARY+import qualified Data.Binary+#endif import Data.Data import Data.ExactPi+import Data.Kind import Data.Semigroup (Semigroup(..)) import Data.Monoid (Monoid(..)) import GHC.Generics@@ -55,12 +60,12 @@  -- | The class of types that can be used to model 'Quantity's that are certain to have a value with -- some dimension.-class Demotable (q :: * -> *) where+class Demotable (q :: Type -> Type) where   demotableOut :: q a -> AnyQuantity a  -- | The class of types that can be used to model 'Quantity's whose 'Dimension's are -- only known dynamically.-class Promotable (q :: * -> *) where+class Promotable (q :: Type -> Type) where   promotableIn :: AnyQuantity a -> q a   promotableOut :: q a -> DynQuantity a @@ -87,7 +92,7 @@  instance (Show a) => Show (AnyQuantity a) where   show (AnyQuantity d a) | d == D.dOne = show a-                         | otherwise   = (show a) ++ " " ++ (show . baseUnitName $ d)+                         | otherwise   = show a ++ " " ++ (show . baseUnitName $ d)  instance HasDynamicDimension (AnyQuantity a) where @@ -112,8 +117,12 @@ -- they may not be added together if their dimensions do not match. instance Num a => Monoid (AnyQuantity a) where   mempty = demoteQuantity (1 Dim.*~ one)-  mappend = (Data.Semigroup.<>)+  mappend = (<>) +#if USE_BINARY+instance (Data.Binary.Binary a) => Data.Binary.Binary (AnyQuantity a)+#endif+ -- | Possibly a 'Quantity' whose 'Dimension' is only known dynamically. -- -- By modeling the absence of a value, this type differs from 'AnyQuantity' in that it may@@ -191,8 +200,12 @@ -- they may not be added together if their dimensions do not match. instance Num a => Monoid (DynQuantity a) where   mempty = demoteQuantity (1 Dim.*~ one)-  mappend = (Data.Semigroup.<>)+  mappend = (<>) +#if USE_BINARY+instance (Data.Binary.Binary a) => Data.Binary.Binary (DynQuantity a)+#endif+ -- | A 'DynQuantity' which does not correspond to a value of any dimension. invalidQuantity :: DynQuantity a invalidQuantity = DynQuantity NoDimension $ error "Attempt to evaluate the value of an invalid quantity."@@ -209,11 +222,11 @@ polydimensionalZero :: (Num a) => DynQuantity a polydimensionalZero = DynQuantity AnyDimension 0 --- Lifts a function which is only valid on dimensionless quantities into a function on DynQuantitys.+-- | Lifts a function which is only valid on dimensionless quantities into a function on 'DynQuantity's. liftDimensionless :: (a -> a) -> DynQuantity a -> DynQuantity a-liftDimensionless f = liftDQ (matchDimensions $ SomeDimension D.dOne) f+liftDimensionless = liftDQ (matchDimensions $ SomeDimension D.dOne) --- Lifts a function on values into a function on DynQuantitys.+-- | Lifts a function on values into a function on 'DynQuantity's. liftDQ :: (DynamicDimension -> DynamicDimension) -- ^ How the function operates on dimensions.        -> (a -> a) -- ^ How the function operates on values.        -> DynQuantity a -> DynQuantity a@@ -221,7 +234,7 @@                                    NoDimension -> invalidQuantity                                    d' -> DynQuantity d' $ fv v --- Lifts a function on values into a function on DynQuantitys.+-- | Lifts a function on values into a function on 'DynQuantity's. -- -- This works by treating polydimensional zeros as dimensionless zeros. If that is not the desired behavior, -- handle polydimensional zeros first and then call this function.@@ -232,7 +245,7 @@                                                           NoDimension -> invalidQuantity                                                           d' -> DynQuantity d' $ fv v1 v2 --- Transforms a dynamic dimension in a way which is always valid+-- | Transforms a dynamic dimension in a way which is always valid. valid :: (Dimension' -> Dimension') -> DynamicDimension -> DynamicDimension valid _ AnyDimension      = AnyDimension valid f (SomeDimension d) = SomeDimension (f d)@@ -248,7 +261,7 @@ constant d (SomeDimension _) = SomeDimension d constant _ _ = NoDimension --- Transforms two dynamic dimensions in a way which is always valid+-- | Transforms two dynamic dimensions in a way which is always valid. valid2 :: (Dimension' -> Dimension' -> Dimension') -> DynamicDimension -> DynamicDimension -> DynamicDimension valid2 _ AnyDimension       (SomeDimension _)  = AnyDimension valid2 _ (SomeDimension _)  AnyDimension       = AnyDimension@@ -264,7 +277,7 @@   deriving (Generic, Typeable)  instance Show AnyUnit where-  show (AnyUnit _ n e) = (show n) ++ " =def= " ++ (show e) ++ " of the SI base unit"+  show (AnyUnit _ n e) = show n ++ " =def= " ++ show e ++ " of the SI base unit"  instance HasDynamicDimension AnyUnit where @@ -281,8 +294,9 @@ -- | 'AnyUnit's form a 'Monoid' under multiplication. instance Monoid AnyUnit where   mempty = demoteUnit' one-  mappend = (Data.Semigroup.<>)+  mappend = (<>) +-- | Extracts the 'UnitName' of an 'AnyUnit'. anyUnitName :: AnyUnit -> UnitName 'NonMetric anyUnitName (AnyUnit _ n _) = n 
src/Numeric/Units/Dimensional/FixedPoint.hs view
@@ -123,7 +123,7 @@ xs *~~ u = fmap (*~ u) xs  -- | Applies '/~' to all values in a functor.-(/~~) :: (Functor f, Real a, Fractional b,  E.MinCtxt s b) => f (SQuantity s d a) -> Unit m d b -> f b+(/~~) :: (Functor f, Real a, Fractional b, E.MinCtxt s b) => f (SQuantity s d a) -> Unit m d b -> f b xs /~~ u = fmap (/~ u) xs  -- | The sum of all elements in a list.@@ -181,11 +181,11 @@ atan2Via :: forall s1 s2 s3 a b c d.(Integral a, RealFloat b, Integral c, E.MinCtxt s1 b, E.MinCtxt s2 b, E.MinCtxt s3 b, KnownDimension d) => Proxy b -> SQuantity s1 d a -> SQuantity s2 d a -> SQuantity s3 DOne c atan2Via _ y x = (*~ siUnit) $ (P.atan2 :: b -> b -> b) (y /~ siUnit) (x /~ siUnit) --- | Lift a function on dimensionless values of a specified intermediate type to operate on possibly scaled dimensionless.+-- | Lift a function on dimensionless values of a specified intermediate type to operate on possibly scaled dimensionless values. liftDimensionlessVia :: forall s1 s2 a b c.(Real a, RealFrac b, Integral c, E.MinCtxt s1 b, E.MinCtxt s2 b) => (b -> b) -> Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c liftDimensionlessVia f _ = (*~ siUnit) . (f :: b -> b) . (/~ siUnit) --- | Lift a periodic function on dimensionless values of a specified intermediate type to operate on possibly scaled dimensionless.+-- | Lift a periodic function on dimensionless values of a specified intermediate type to operate on possibly scaled dimensionless values. -- -- If the scale factor of the input type is an exact integer divisor of the function's period, the argument -- will be clamped via an integer `mod` operation prior to applying the function to avoid errors introduced by a floating point modulus.@@ -342,12 +342,12 @@  -- | Twice 'pi'. ----- For background on 'tau' see http://tauday.com/tau-manifesto (but also--- feel free to review http://www.thepimanifesto.com).+-- For background on 'tau' see [The Tau Manifesto](https://tauday.com/tau-manifesto) (but also+-- feel free to review [The Pi Manifesto](https://web.archive.org/web/20200926221249/http://www.thepimanifesto.com/)). tau :: (Integral a, E.KnownExactPi s) => SQuantity s DOne a tau = rescale (epsilon :: SQuantity (E.ExactNatural 2 E.* E.Pi) DOne Integer) --- | The least positive representable value in a given fixed-point scaled quantity type.+-- | The smallest positive representable value in a given fixed-point scaled quantity type. epsilon :: (Integral a) => SQuantity s d a epsilon = Quantity 1 
src/Numeric/Units/Dimensional/Float.hs view
@@ -8,8 +8,8 @@ Defines convenience functions for inspecting and manipulating quantities with 'RealFloat' floating-point representations. -The dimensionally-typed versions of functions from Patrick Perry's @ieee754@ package-copy that package's API as closely as possible, by permission. In turn they are based on+The dimensionally-typed versions of functions from Patrick Perry's [ieee754](https://hackage.haskell.org/package/ieee754) package+copy that packages API as closely as possible, by permission. In turn they are based on the @tango@ math library for the D language.  -}@@ -45,6 +45,7 @@ import Numeric.Units.Dimensional.Coercion  -- $setup+-- >>> :set -fno-warn-type-defaults -- >>> :set -XExtendedDefaultRules -- >>> :set -XNegativeLiterals @@ -104,25 +105,25 @@ -- -- >>> let x = 3 *~ meter -- >>> scaleFloat 3 x--- 24.0 m+-- 24.0 m scaleFloat :: RealFloat a => Int -> Quantity d a -> Quantity d a scaleFloat x = Quantity . P.scaleFloat x . unQuantity  -- | An infinite floating-point quantity. infinity :: IEEE a => Quantity d a-infinity = Quantity $ F.infinity+infinity = Quantity F.infinity  -- | The smallest representable positive quantity whose representation is normalized. minNormal :: IEEE a => Quantity d a-minNormal = Quantity $ F.minNormal+minNormal = Quantity F.minNormal  -- | The largest representable finite floating-point quantity. maxFinite :: IEEE a => Quantity d a-maxFinite = Quantity $ F.maxFinite+maxFinite = Quantity F.maxFinite  -- | The smallest positive value @x@ such that @_1 + x@ is representable. epsilon :: IEEE a => Dimensionless a-epsilon = Quantity $ F.epsilon+epsilon = Quantity F.epsilon  -- | @copySign x y@ returns the quantity @x@ with its sign changed to match that of @y@. copySign :: IEEE a => Quantity d a -> Quantity d a -> Quantity d a@@ -148,7 +149,7 @@  -- | Default @NaN@ quantity. nan :: IEEE a => Quantity d a-nan = Quantity $ F.nan+nan = Quantity F.nan  -- | Quiet @NaN@ quantity with a positive integer payload. -- Payload must be less than 'maxNaNPayload' of the representation type.
src/Numeric/Units/Dimensional/Functor.hs view
@@ -1,14 +1,6 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_HADDOCK show-extensions #-} -{-# LANGUAGE CPP #-}-#if MIN_VERSION_base(4,8,0)--- OverlappingInstances was deprecated by GHC 7.10 in favor of OVERLAPPING pragmas.-#else-{-# LANGUAGE OverlappingInstances #-}-{-# OPTIONS_GHC -fno-warn-unrecognised-pragmas #-}-#endif- {- |    Copyright  : Copyright (C) 2006-2018 Bjorn Buckwalter    License    : BSD3
src/Numeric/Units/Dimensional/Internal.hs view
@@ -26,15 +26,16 @@ where  import Control.Applicative-import Control.DeepSeq-import Control.Monad (liftM)+import Control.DeepSeq (NFData) import Data.AEq (AEq)+#if USE_BINARY+import qualified Data.Binary+#endif import Data.Coerce (coerce) import Data.Data+import Data.Kind import Data.ExactPi-#if MIN_VERSION_base(4,9,0) import Data.Functor.Classes (Eq1(..), Ord1(..))-#endif import qualified Data.ExactPi.TypeLevel as E import Data.Monoid (Monoid(..)) import Data.Semigroup (Semigroup(..))@@ -59,6 +60,7 @@  -- $setup -- >>> :set -XNoImplicitPrelude+-- >>> :set -fno-warn-type-defaults -- >>> import Numeric.Units.Dimensional.Prelude  -- | A unit of measurement.@@ -78,12 +80,12 @@ -- Each validly constructed type of kind 'Variant' has a 'KnownVariant' instance. class KnownVariant (v :: Variant) where   -- | A dimensional value, either a 'Quantity' or a 'Unit', parameterized by its 'Dimension' and representation.-  data Dimensional v :: Dimension -> * -> *+  data Dimensional v :: Dimension -> Type -> Type   -- | A scale factor by which the numerical value of this dimensional value is implicitly multiplied.   type ScaleFactor v :: E.ExactPi'   extractValue :: Dimensional v d a -> (a, Maybe ExactPi)   extractName :: Dimensional v d a -> Maybe (UnitName 'NonMetric)-  injectValue :: (Maybe (UnitName 'NonMetric)) -> (a, Maybe ExactPi) -> Dimensional v d a+  injectValue :: Maybe (UnitName 'NonMetric) -> (a, Maybe ExactPi) -> Dimensional v d a   -- | Maps over the underlying representation of a dimensional value.   -- The caller is responsible for ensuring that the supplied function respects the dimensional abstraction.   -- This means that the function must preserve numerical values, or linearly scale them while preserving the origin.@@ -93,11 +95,7 @@  instance KnownVariant ('DQuantity s) where   newtype Dimensional ('DQuantity s) d a = Quantity a-    deriving (Eq, Ord, AEq, Data, Generic, Generic1-#if MIN_VERSION_base(4,8,0)-     , Typeable -- GHC 7.8 doesn't support deriving this instance-#endif-    )+    deriving (Eq, Ord, AEq, Data, Generic, Generic1, Typeable)   type (ScaleFactor ('DQuantity s)) = s   extractValue (Quantity x) = (x, Nothing)   extractName _ = Nothing@@ -106,11 +104,7 @@  instance (Typeable m) => KnownVariant ('DUnit m) where   data Dimensional ('DUnit m) d a = Unit !(UnitName m) !ExactPi !a-    deriving (Generic, Generic1-#if MIN_VERSION_base(4,8,0)-     , Typeable -- GHC 7.8 doesn't support deriving this instance-#endif-    )+    deriving (Generic, Generic1, Typeable)   type (ScaleFactor ('DUnit m)) = E.One   extractValue (Unit _ e x) = (x, Just e)   extractName (Unit n _ _) = Just . Name.weaken $ n@@ -124,13 +118,11 @@   minBound = Quantity minBound   maxBound = Quantity maxBound -#if MIN_VERSION_base(4,9,0) instance Eq1 (SQuantity s d) where   liftEq = coerce  instance Ord1 (SQuantity s d) where   liftCompare = coerce-#endif  instance HasInterchangeName (Unit m d a) where   interchangeName (Unit n _ _) = interchangeName n@@ -147,8 +139,12 @@ -- | 'Quantity's of a given 'Dimension' form a 'Monoid' under addition. instance (Num a) => Monoid (SQuantity s d a) where   mempty = Quantity 0-  mappend = liftQ2 (+)+  mappend = (<>) +#if USE_BINARY+deriving instance (Data.Binary.Binary a) => Data.Binary.Binary (SQuantity s d a)+#endif+ {-  = Dimensionless =@@ -175,13 +171,13 @@ instance NFData a => NFData (Quantity d a) -- instance is derived from Generic instance  instance Storable a => Storable (SQuantity s d a) where-  sizeOf _ = sizeOf (undefined::a)+  sizeOf _ = sizeOf (undefined :: a)   {-# INLINE sizeOf #-}-  alignment _ = alignment (undefined::a)+  alignment _ = alignment (undefined :: a)   {-# INLINE alignment #-}   poke ptr = poke (castPtr ptr :: Ptr a) . coerce   {-# INLINE poke #-}-  peek ptr = liftM Quantity (peek (castPtr ptr :: Ptr a))+  peek ptr = fmap Quantity (peek (castPtr ptr :: Ptr a))   {-# INLINE peek #-}  {-@@ -198,9 +194,9 @@   {-# INLINE basicUnsafeSlice #-}   basicOverlaps u v    = M.basicOverlaps (unMVQ u) (unMVQ v)   {-# INLINE basicOverlaps #-}-  basicUnsafeNew       = liftM MV_Quantity . M.basicUnsafeNew+  basicUnsafeNew       = fmap MV_Quantity . M.basicUnsafeNew   {-# INLINE basicUnsafeNew #-}-  basicUnsafeRead v    = liftM Quantity . M.basicUnsafeRead (unMVQ v)+  basicUnsafeRead v    = fmap Quantity . M.basicUnsafeRead (unMVQ v)   {-# INLINE basicUnsafeRead #-}   basicUnsafeWrite v i = M.basicUnsafeWrite (unMVQ v) i . coerce   {-# INLINE basicUnsafeWrite #-}@@ -210,15 +206,15 @@ #endif  instance (G.Vector U.Vector a) => G.Vector U.Vector (SQuantity s d a) where-  basicUnsafeFreeze    = liftM V_Quantity  . G.basicUnsafeFreeze . unMVQ+  basicUnsafeFreeze    = fmap V_Quantity  . G.basicUnsafeFreeze . unMVQ   {-# INLINE basicUnsafeFreeze #-}-  basicUnsafeThaw      = liftM MV_Quantity . G.basicUnsafeThaw   . unVQ+  basicUnsafeThaw      = fmap MV_Quantity . G.basicUnsafeThaw   . unVQ   {-# INLINE basicUnsafeThaw #-}   basicLength          = G.basicLength . unVQ   {-# INLINE basicLength #-}   basicUnsafeSlice m n = V_Quantity . G.basicUnsafeSlice m n . unVQ   {-# INLINE basicUnsafeSlice #-}-  basicUnsafeIndexM v  = liftM Quantity . G.basicUnsafeIndexM (unVQ v)+  basicUnsafeIndexM v  = fmap Quantity . G.basicUnsafeIndexM (unVQ v)   {-# INLINE basicUnsafeIndexM #-}  {-@@ -226,6 +222,7 @@ quantities. The SI unit of the quantity is inferred from its dimension. -}+-- | Uses non-breaking spaces between the value and the unit, and within the unit name. instance (KnownDimension d, E.KnownExactPi s, Show a, Real a) => Show (SQuantity s d a) where   show (Quantity x) | isExactOne s' = show x ++ showName n                     | otherwise = "Quantity " ++ show x ++ " {- " ++ show q ++ " -}"@@ -237,23 +234,26 @@  -- | Shows the value of a 'Quantity' expressed in a specified 'Unit' of the same 'Dimension'. ----- >>> showIn watt $ (37 *~ volt) * (4 *~ ampere)--- "148.0 W"+-- Uses non-breaking spaces between the value and the unit, and within the unit name.+--+-- >>> putStrLn $ showIn watt $ (37 *~ volt) * (4 *~ ampere)+-- 148.0 W showIn :: (Show a, Fractional a) => Unit m d a -> Quantity d a -> String showIn (Unit n _ y) (Quantity x) = show (x / y) ++ (showName . Name.weaken $ n)  showName :: UnitName 'NonMetric -> String showName n | n == nOne = ""-           | otherwise = " " ++ show n+           | otherwise = "\xA0" ++ show n +-- | Unit names are shown with non-breaking spaces. instance (Show a) => Show (Unit m d a) where   show (Unit n e x) = "The unit " ++ show n ++ ", with value " ++ show e ++ " (or " ++ show x ++ ")"  -- Operates on a dimensional value using a unary operation on values, possibly yielding a Unit.-liftD :: (KnownVariant v1, KnownVariant v2) => (ExactPi -> ExactPi) -> (a -> b) -> UnitNameTransformer -> (Dimensional v1 d1 a) -> (Dimensional v2 d2 b)+liftD :: (KnownVariant v1, KnownVariant v2) => (ExactPi -> ExactPi) -> (a -> b) -> UnitNameTransformer -> Dimensional v1 d1 a -> Dimensional v2 d2 b liftD fe f nt x = let (x', e') = extractValue x                       n = extractName x-                      n' = (liftA nt) n+                      n' = fmap nt n                    in injectValue n' (f x', fmap fe e')  -- Operates on a dimensional value using a unary operation on values, yielding a Quantity.@@ -266,7 +266,7 @@                            (x2', e2') = extractValue x2                            n1 = extractName x1                            n2 = extractName x2-                           n' = (liftA2 nt) n1 n2+                           n' = liftA2 nt n1 n2                         in injectValue n' (f x1' x2', fe <$> e1' <*> e2')  -- Combines two dimensional values using a binary operation on values, yielding a Quantity.
src/Numeric/Units/Dimensional/NonSI.hs view
@@ -27,10 +27,10 @@  = References -1. #note1# http://physics.nist.gov/Pubs/SP811/-2. #note2# http://www.iau.org/science/publications/proceedings_rules/units/-3. #note3# http://en.m.wikipedia.org/wiki/Pressure-4. #note4# http://en.m.wikipedia.org/wiki/Torr+1. #note1# https://www.nist.gov/pml/special-publication-811+2. #note2# https://www.iau.org/publications/proceedings_rules/units/+3. #note3# https://en.wikipedia.org/wiki/Pressure+4. #note4# https://en.wikipedia.org/wiki/Torr  -} @@ -38,7 +38,9 @@ (   -- * Units Defined By Experiment   -- $values-obtained-experimentally-  electronVolt, unifiedAtomicMassUnit, dalton,+  electronVolt, calorie, unifiedAtomicMassUnit, dalton,+  -- * Dimensionless Units+  percent,   -- * Standard Gravity   gee,   -- * Inch-pound Units@@ -54,7 +56,7 @@   usSurveyFoot, usSurveyInch, usSurveyMil, usSurveyYard, usSurveyMile, usSurveyAcre,   -- * Years   -- $year-  year, century,+  year, decade, century, millennium,   -- * Pressure Units   -- $pressure-units   bar, atmosphere, technicalAtmosphere, mmHg, inHg, inHg_UCUM, inHg_NIST, torr,@@ -83,6 +85,7 @@ import qualified Prelude  -- $setup+-- >>> :set -fno-warn-type-defaults -- >>> import Data.ExactPi -- >>> import Data.Function (on) -- >>> import Numeric.Units.Dimensional.Coercion@@ -97,7 +100,7 @@ From Table 7, units accepted for use with the SI whose values in SI units are obtained experimentally. -When <#note1 [1]> was published the electron volt had a standard combined+When <#note1 [1]> was published, the electron volt had a standard combined uncertainity of 0.00000049e-19 J and the unified atomic mass unit had a combined uncertainty of 0.0000010e-27 kg. @@ -106,12 +109,26 @@ electronVolt :: Floating a => Unit 'Metric DEnergy a electronVolt = mkUnitR (ucumMetric "eV" "eV" "electron volt") 1.60217733e-19 $ joule +calorie :: Floating a => Unit 'Metric DEnergy a+calorie = mkUnitR (ucumMetric "cal" "cal" "calorie") 4.184 $ joule+ unifiedAtomicMassUnit :: Floating a => Unit 'Metric DMass a unifiedAtomicMassUnit = mkUnitR (ucumMetric "u" "u" "atomic mass unit") 1.6605402e-27 $ kilo gram  dalton :: Floating a => Unit 'Metric DMass a dalton = mkUnitR (ucumMetric "u" "Da" "Dalton") 1 $ unifiedAtomicMassUnit +-- | One percent is one hundrendth.+--+-- The dimensionless number 0.01, represented by the symbol %, is commonly used as a dimensionless unit.+--+-- See section 7.10.2 of the <#note1 [1]> for further information.+--+-- >>> 1 *~ percent+-- 1.0e-2+percent :: (Fractional a) => Unit 'NonMetric DOne a+percent = mkUnitQ (ucum "%" "%" "percent") (1 Prelude./ 100) one+ -- | One gee is the standard value of the acceleration due to gravity at the -- Earth's surface, as standardized by CIPM. --@@ -121,10 +138,10 @@ -- See <https://en.wikipedia.org/wiki/Standard_gravity here> for further information. -- -- >>> 1 *~ gee--- 9.80665 m s^-2+-- 9.80665 m s^-2 -- -- >>> 1 *~ gee :: Acceleration Rational--- 196133 % 20000 m s^-2+-- 196133 % 20000 m s^-2 gee :: Fractional a => Unit 'Metric DAcceleration a gee = mkUnitQ (ucumMetric "[g]" "g" "gee") 9.80665 $ meter / second ^ pos2 @@ -137,12 +154,12 @@ -- See <https://en.wikipedia.org/wiki/Foot_%28unit%29#International_foot here> for further information. -- -- >>> 1 *~ foot--- 0.3048 m+-- 0.3048 m -- -- prop> 3 *~ foot === 1 *~ yard -- -- >>> 1 *~ foot :: Length Rational--- 381 % 1250 m+-- 381 % 1250 m foot :: Fractional a => Unit 'NonMetric DLength a foot = mkUnitQ (ucum "[ft_i]" "ft" "foot") (1 Prelude./ 3) $ yard @@ -153,12 +170,12 @@ -- See <https://en.wikipedia.org/wiki/Inch#Modern_standardisation here> for further information. -- -- >>> 1 *~ inch--- 2.54e-2 m+-- 2.54e-2 m -- -- prop> 12 *~ inch === 1 *~ foot -- -- >>> 1 *~ inch :: Length Rational--- 127 % 5000 m+-- 127 % 5000 m inch :: Fractional a => Unit 'NonMetric DLength a inch = mkUnitQ (ucum "[in_i]" "in" "inch") (1 Prelude./ 12) $ foot @@ -169,12 +186,12 @@ -- See <https://en.wikipedia.org/wiki/Thousandth_of_an_inch here> for further information. -- -- >>> 1 *~ mil--- 2.54e-5 m+-- 2.54e-5 m -- -- prop> 1000 *~ mil === 1 *~ inch -- -- >>> 1 *~ mil :: Length Rational--- 127 % 5000000 m+-- 127 % 5000000 m mil :: Fractional a => Unit 'NonMetric DLength a mil = mkUnitQ (ucum "[mil_i]" "mil" "mil") 0.001 $ inch @@ -184,10 +201,10 @@ -- See <https://en.wikipedia.org/wiki/Yard here> for further information. -- -- >>> 1 *~ yard--- 0.9144 m+-- 0.9144 m -- -- >>> 1 *~ yard :: Length Rational--- 1143 % 1250 m+-- 1143 % 1250 m yard :: (Fractional a) => Unit 'NonMetric DLength a yard = mkUnitQ (ucum "[yd_i]" "yd" "yard") 0.9144 $ meter @@ -198,12 +215,12 @@ -- See <https://en.wikipedia.org/wiki/Mile#International_mile here> for further information. -- -- >>> 1 *~ mile--- 1609.344 m+-- 1609.344 m -- -- prop> 1 *~ mile === 5280 *~ foot -- -- >>> 1 *~ mile :: Length Rational--- 201168 % 125 m+-- 201168 % 125 m mile :: (Fractional a) => Unit 'NonMetric DLength a mile = mkUnitQ (ucum "[mi_i]" "mi" "mile") 5280 $ foot @@ -216,12 +233,12 @@ -- See <https://en.wikipedia.org/wiki/Acre#Differences_between_international_and_US_survey_acres here> for further information. -- -- >>> 1 *~ acre--- 4046.8564224 m^2+-- 4046.8564224 m^2 -- -- prop> 1 *~ acre === 43560 *~ foot ^ pos2 -- -- >>> 1 *~ acre :: Area Rational--- 316160658 % 78125 m^2+-- 316160658 % 78125 m^2 acre :: (Fractional a) => Unit 'NonMetric DArea a acre = mkUnitQ (dimensionalAtom "[acr_i]" "ac" "acre") 43560 $ square foot @@ -233,10 +250,10 @@ -- See <https://en.wikipedia.org/wiki/Foot_%28unit%29#US_survey_foot here> for further information. -- -- >>> 1 *~ usSurveyFoot--- 0.3048006096012192 m+-- 0.3048006096012192 m -- -- >>> 1 *~ usSurveyFoot :: Length Rational--- 1200 % 3937 m+-- 1200 % 3937 m usSurveyFoot :: Fractional a => Unit 'NonMetric DLength a usSurveyFoot = mkUnitQ (ucum "[ft_us]" "ft" "foot") (1200 Prelude./ 3937) $ meter @@ -248,12 +265,12 @@ -- See <https://en.wikipedia.org/wiki/Inch here> for further information. -- -- >>> 1 *~ usSurveyInch--- 2.54000508001016e-2 m+-- 2.54000508001016e-2 m -- -- prop> 12 *~ usSurveyInch === 1 *~ usSurveyFoot -- -- >>> 1 *~ usSurveyInch :: Length Rational--- 100 % 3937 m+-- 100 % 3937 m usSurveyInch :: Fractional a => Unit 'NonMetric DLength a usSurveyInch = mkUnitQ (ucum "[in_us]" "in" "inch") (1 Prelude./ 12) $ usSurveyFoot @@ -265,12 +282,12 @@ -- See <https://en.wikipedia.org/wiki/Thousandth_of_an_inch here> for further information. -- -- >>> 1 *~ usSurveyMil--- 2.54000508001016e-5 m+-- 2.54000508001016e-5 m -- -- prop> 1000 *~ usSurveyMil === 1 *~ usSurveyInch -- -- >>> 1 *~ usSurveyMil :: Length Rational--- 1 % 39370 m+-- 1 % 39370 m usSurveyMil :: Fractional a => Unit 'NonMetric DLength a usSurveyMil = mkUnitQ (ucum "[mil_us]" "mil" "mil") 0.001 $ usSurveyInch @@ -282,12 +299,12 @@ -- See <https://en.wikipedia.org/wiki/Yard here> for further information. -- -- >>> 1 *~ usSurveyYard--- 0.9144018288036576 m+-- 0.9144018288036576 m -- -- prop> 1 *~ usSurveyYard === 3 *~ usSurveyFoot -- -- >>> 1 *~ usSurveyYard :: Length Rational--- 3600 % 3937 m+-- 3600 % 3937 m usSurveyYard :: (Fractional a) => Unit 'NonMetric DLength a usSurveyYard = mkUnitQ (ucum "[yd_us]" "yd" "yard") 3 $ usSurveyFoot @@ -299,12 +316,12 @@ -- See <https://en.wikipedia.org/wiki/Mile#US_survey_mile here> for further information. -- -- >>> 1 *~ usSurveyMile--- 1609.3472186944373 m+-- 1609.3472186944373 m -- -- prop> 1 *~ usSurveyMile === 5280 *~ usSurveyFoot -- -- >>> 1 *~ usSurveyMile :: Length Rational--- 6336000 % 3937 m+-- 6336000 % 3937 m usSurveyMile :: (Fractional a) => Unit 'NonMetric DLength a usSurveyMile = mkUnitQ (ucum "[mi_us]" "mi" "mile") 5280 $ usSurveyFoot @@ -317,12 +334,12 @@ -- See <https://en.wikipedia.org/wiki/Acre#Differences_between_international_and_US_survey_acres here> for further information. -- -- >>> 1 *~ usSurveyAcre--- 4046.872609874252 m^2+-- 4046.872609874252 m^2 -- -- prop> 1 *~ usSurveyAcre === 43560 *~ usSurveyFoot ^ pos2 -- -- >>> 1 *~ usSurveyAcre :: Area Rational--- 62726400000 % 15499969 m^2+-- 62726400000 % 15499969 m^2 usSurveyAcre :: (Fractional a) => Unit 'NonMetric DArea a usSurveyAcre = mkUnitQ (ucum "[acr_us]" "ac" "acre") 43560 $ square usSurveyFoot @@ -332,10 +349,10 @@ -- See <https://en.wikipedia.org/wiki/Avoirdupois#Internationalization here> for further information. -- -- >>> 1 *~ poundMass--- 0.45359237 kg+-- 0.45359237 kg -- -- >>> 1 *~ poundMass :: Mass Rational--- 45359237 % 100000000 kg+-- 45359237 % 100000000 kg poundMass :: Fractional a => Unit 'NonMetric DMass a poundMass = mkUnitQ (ucum "[lb_av]" "lb" "pound") 0.45359237 $ kilo gram @@ -344,12 +361,12 @@ -- See <https://en.wikipedia.org/wiki/Ounce#International_avoirdupois_ounce here> for further information. -- -- >>> 1 *~ ounce--- 2.8349523125e-2 kg+-- 2.8349523125e-2 kg -- -- prop> 16 *~ ounce === 1 *~ poundMass -- -- >>> 1 *~ ounce :: Mass Rational--- 45359237 % 1600000000 kg+-- 45359237 % 1600000000 kg ounce :: Fractional a => Unit 'NonMetric DMass a ounce = mkUnitQ (ucum "[oz_av]" "oz" "ounce") (1 Prelude./ 16) $ poundMass @@ -358,10 +375,10 @@ -- See <https://en.wikipedia.org/wiki/Short_ton#United_States here> for further information. -- -- >>> 1 *~ shortTon--- 907.18474 kg+-- 907.18474 kg -- -- >>> 1 *~ shortTon :: Mass Rational--- 45359237 % 50000 kg+-- 45359237 % 50000 kg shortTon :: Fractional a => Unit 'NonMetric DMass a shortTon = mkUnitQ (ucum "[ston_av]" "ton" "short ton") 2000 $ poundMass @@ -374,12 +391,12 @@ -- See <https://en.wikipedia.org/wiki/Pound_%28force%29 here> for further information. -- -- >>> 1 *~ poundForce--- 4.4482216152605 m kg s^-2+-- 4.4482216152605 m kg s^-2 -- -- prop> 1 *~ poundForce === 1 *~ poundMass * (1 *~ gee) -- -- >>> 1 *~ poundForce :: Force Rational--- 8896443230521 % 2000000000000 m kg s^-2+-- 8896443230521 % 2000000000000 m kg s^-2 poundForce :: Fractional a => Unit 'NonMetric DForce a poundForce = mkUnitQ (ucum "[lbf_av]" "lbf" "pound force") 1 $ poundMass * gee @@ -390,12 +407,12 @@ -- See <https://en.wikipedia.org/wiki/Horsepower#Mechanical_horsepower here> for further information. -- -- >>> 1 *~ horsepower--- 745.6998715822702 m^2 kg s^-3+-- 745.6998715822702 m^2 kg s^-3 -- -- prop> 1 *~ horsepower === 550 *~ poundForce * (1 *~ foot) / (1 *~ second) -- -- >>> 1 *~ horsepower :: Power Rational--- 37284993579113511 % 50000000000000 m^2 kg s^-3+-- 37284993579113511 % 50000000000000 m^2 kg s^-3 horsepower :: Fractional a => Unit 'NonMetric DPower a horsepower = mkUnitQ (ucum "[HP]" "hp" "horsepower") 550 $ foot * poundForce / second @@ -407,10 +424,10 @@ -- See <https://en.wikipedia.org/wiki/Slug_%28mass%29 here> for further information. -- -- >>> 1 *~ slug--- 14.593902937206364 kg+-- 14.593902937206364 kg -- -- >>> 1 *~ slug :: Mass Rational--- 8896443230521 % 609600000000 kg+-- 8896443230521 % 609600000000 kg slug :: Fractional a => Unit 'NonMetric DMass a slug = mkUnitQ (dimensionalAtom "slug" "slug" "slug") 1 $ poundForce * (second^pos2) / foot @@ -419,10 +436,10 @@ -- See <https://en.wikipedia.org/wiki/Pounds_per_square_inch here> for further information. -- -- >>> 1 *~ psi--- 6894.757293168362 m^-1 kg s^-2+-- 6894.757293168362 m^-1 kg s^-2 -- -- >>> 1 *~ psi :: Pressure Rational--- 8896443230521 % 1290320000 m^-1 kg s^-2+-- 8896443230521 % 1290320000 m^-1 kg s^-2 psi :: Fractional a => Unit 'NonMetric DPressure a psi = mkUnitQ (ucum "[psi]" "psi" "pound per square inch") 1 $ poundForce / inch ^ pos2 @@ -433,10 +450,10 @@ -- See <https://en.wikipedia.org/wiki/Nautical_mile here> for further information. -- -- >>> 1 *~ nauticalMile--- 1852.0 m+-- 1852.0 m -- -- >>> 1 *~ nauticalMile :: Length Rational--- 1852 % 1 m+-- 1852 % 1 m nauticalMile :: (Num a) => Unit 'NonMetric DLength a nauticalMile = mkUnitZ (ucum "[nmi_i]" "NM" "nautical mile") 1852 $ meter @@ -445,14 +462,14 @@ -- See <https://en.wikipedia.org/wiki/Knot_%28unit%29 here> for further information. -- -- >>> 1 *~ knot--- 0.5144444444444445 m s^-1+-- 0.5144444444444445 m s^-1 -- -- >>> 1 *~ knot :: Velocity Rational--- 463 % 900 m s^-1+-- 463 % 900 m s^-1 knot :: (Fractional a) => Unit 'NonMetric DVelocity a knot = mkUnitQ (ucum "[kt_i]" "kt" "knot") 1 $ nauticalMile / hour --- | One revolution is an angle equal to 2 pi radians; a full circle.+-- | One revolution is an angle equal to 2*pi radians; a full circle. -- -- See <https://en.wikipedia.org/wiki/Turn_%28geometry%29 here> for further information. --@@ -481,10 +498,10 @@ -- See <https://en.wikipedia.org/wiki/British_thermal_unit#Definitions here> for further information. -- -- >>> 1 *~ btu--- 1055.05585262 m^2 kg s^-2+-- 1055.05585262 m^2 kg s^-2 -- -- >>> 1 *~ btu :: Energy Rational--- 52752792631 % 50000000 m^2 kg s^-2+-- 52752792631 % 50000000 m^2 kg s^-2 btu :: Fractional a => Unit 'NonMetric DEnergy a btu = mkUnitQ (ucum "[Btu_IT]" "btu" "British thermal unit") 1055.05585262 $ joule @@ -494,33 +511,63 @@ The IAU recommends <#note2 [2]> that:    Although there are several different kinds of year (as there are-  several kinds of day), it is best to regard a year as a julian-  year of 365.25 days (31.5576 Ms) unless otherwise specified.+  several kinds of day), it is best to regard a year as a Julian+  year of 365.25 days (31557600 s) unless otherwise specified.  -} --- | One mean Julian year is a unit of measurement of time defined as exactly 365.25 days of 86 400 'second's each.+-- | One Julian year is a unit of measurement of time defined as exactly 365.25 days of 86 400 'second's each. -- -- See <https://en.wikipedia.org/wiki/Julian_year_%28astronomy%29 here> for further information. --+-- prop> 1 *~ year === 365.25 *~ day+-- -- >>> 1 *~ year--- 3.15576e7 s+-- 3.15576e7 s -- -- >>> 1 *~ year :: Time Rational--- 31557600 % 1 s+-- 31557600 % 1 s year :: Num a => Unit 'NonMetric DTime a year = mkUnitZ (ucum "a_j" "a" "mean Julian year") 31557600 $ second --- | One mean Julian century is one hundred mean Julian 'year's.+-- | One Julian decade is ten Julian 'year's. --+-- prop> 1 *~ decade === 10 *~ year+--+-- >>> 1 *~ decade+-- 3.15576e8 s+--+-- >>> 1 *~ decade :: Time Rational+-- 315576000 % 1 s+decade :: Num a => Unit 'NonMetric DTime a+decade = mkUnitZ (dimensionalAtom "d_j" "dec" "mean Julian decade") 10 $ year++-- | One Julian century is one hundred Julian 'year's, or 35 525 'day's of 86 400 'second's each.+--+-- prop> 1 *~ century === 100 *~ year+--+-- prop> 1 *~ century === 36525 *~ day+-- -- >>> 1 *~ century--- 3.15576e9 s+-- 3.15576e9 s -- -- >>> 1 *~ century :: Time Rational--- 3155760000 % 1 s+-- 3155760000 % 1 s century :: Num a => Unit 'NonMetric DTime a century = mkUnitZ (dimensionalAtom "c_j" "cen" "mean Julian century") 100 $ year +-- | One Julian millennium is one thousand Julian 'year's.+--+-- prop> 1 *~ millennium === 1000 *~ year+--+-- >>> 1 *~ millennium+-- 3.15576e10 s+--+-- >>> 1 *~ millennium :: Time Rational+-- 31557600000 % 1 s+millennium :: Num a => Unit 'NonMetric DTime a+millennium = mkUnitZ (dimensionalAtom "m_j" "mil" "mean Julian millennium") 1000 $ year+ {- $pressure-units It seems that nearly every area of application has its own customary unit for measuring pressure. We include some of the common ones here. 'psi' was defined earlier.@@ -533,10 +580,10 @@ --  It is about equal to the atmospheric pressure on Earth at sea level. -- -- >>> 1 *~ bar--- 100000.0 m^-1 kg s^-2+-- 100000.0 m^-1 kg s^-2 -- -- >>> 1 *~ bar :: Pressure Rational--- 100000 % 1 m^-1 kg s^-2+-- 100000 % 1 m^-1 kg s^-2 bar :: (Num a) => Unit 'Metric DPressure a bar = mkUnitZ (ucumMetric "bar" "bar" "bar") 1e5 $ pascal @@ -549,10 +596,10 @@ --  level. -- -- >>> 1 *~ atmosphere--- 101325.0 m^-1 kg s^-2+-- 101325.0 m^-1 kg s^-2 -- -- >>> 1 *~ atmosphere :: Pressure Rational--- 101325 % 1 m^-1 kg s^-2+-- 101325 % 1 m^-1 kg s^-2 atmosphere :: (Num a) => Unit 'NonMetric DPressure a atmosphere = mkUnitZ (ucum "atm" "atm" "standard atmosphere") 101325 $ pascal @@ -564,10 +611,10 @@ --  to one kilogram-force per square centimeter. -- -- >>> 1 *~ technicalAtmosphere--- 98066.5 m^-1 kg s^-2+-- 98066.5 m^-1 kg s^-2 -- -- >>> 1 *~ technicalAtmosphere :: Pressure Rational--- 196133 % 2 m^-1 kg s^-2+-- 196133 % 2 m^-1 kg s^-2 technicalAtmosphere :: (Fractional a) => Unit 'NonMetric DPressure a technicalAtmosphere = mkUnitQ (ucum "att" "at" "technical atmosphere") 1 $ kilo gram * gee * centi meter ^ neg2 @@ -583,10 +630,10 @@ -- at 0 deg. Under most conditions, 1 mmHg is approximately equal to 1 'torr'. -- -- >>> 1 *~ mmHg--- 133.322 m^-1 kg s^-2+-- 133.322 m^-1 kg s^-2 -- -- >>> 1 *~ mmHg :: Pressure Rational--- 66661 % 500 m^-1 kg s^-2+-- 66661 % 500 m^-1 kg s^-2 mmHg :: (Fractional a) => Unit 'NonMetric DPressure a mmHg = milli mHg @@ -601,10 +648,10 @@ -- This is the value defined by UCUM. For the value defined by NIST, see 'inHg_NIST'. -- -- >>> 1 *~ inHg--- 3386.3788 m^-1 kg s^-2+-- 3386.3788 m^-1 kg s^-2 -- -- >>> 1 *~ inHg :: Pressure Rational--- 8465947 % 2500 m^-1 kg s^-2+-- 8465947 % 2500 m^-1 kg s^-2 inHg :: (Fractional a) => Unit 'NonMetric DPressure a inHg = inHg_UCUM @@ -616,10 +663,10 @@ -- This is the value defined by UCUM. For the value defined by NIST, see 'inHg_NIST'. -- -- >>> 1 *~ inHg_UCUM--- 3386.3788 m^-1 kg s^-2+-- 3386.3788 m^-1 kg s^-2 -- -- >>> 1 *~ inHg_UCUM :: Pressure Rational--- 8465947 % 2500 m^-1 kg s^-2+-- 8465947 % 2500 m^-1 kg s^-2 inHg_UCUM :: (Fractional a) => Unit 'NonMetric DPressure a inHg_UCUM = mkUnitQ (ucum "[in_i'Hg]" "in Hg" "inch of mercury") 1 $ mHg * inch / meter @@ -631,10 +678,10 @@ -- This is the value defined by NIST. For the value defined by UCUM, see 'inHg_UCUM'. -- -- >>> 1 *~ inHg_NIST--- 3386.389 m^-1 kg s^-2+-- 3386.389 m^-1 kg s^-2 -- -- >>> 1 *~ inHg_NIST :: Pressure Rational--- 3386389 % 1000 m^-1 kg s^-2+-- 3386389 % 1000 m^-1 kg s^-2 inHg_NIST :: (Fractional a) => Unit 'NonMetric DPressure a inHg_NIST = mkUnitQ (dimensionalAtom "[in_i'Hg_NIST]" "in Hg" "inch of mercury") 3.386389e3 $ pascal @@ -643,10 +690,10 @@ -- See <https://en.wikipedia.org/wiki/Torr here> for further information. -- -- >>> 1 *~ torr--- 133.32236842105263 m^-1 kg s^-2+-- 133.32236842105263 m^-1 kg s^-2 -- -- >>> 1 *~ torr :: Pressure Rational--- 20265 % 152 m^-1 kg s^-2+-- 20265 % 152 m^-1 kg s^-2 torr :: (Fractional a) => Unit 'NonMetric DPressure a torr = mkUnitQ (dimensionalAtom "Torr" "Torr" "Torr") (1 Prelude./ 760) $ atmosphere @@ -656,10 +703,10 @@ -- See <https://en.wikipedia.org/wiki/Rad_%28unit%29 here> for further information. -- -- >>> 1 *~ rad--- 1.0e-2 m^2 s^-2+-- 1.0e-2 m^2 s^-2 -- -- >>> 1 *~ rad :: AbsorbedDose Rational--- 1 % 100 m^2 s^-2+-- 1 % 100 m^2 s^-2 rad :: (Fractional a) => Unit 'Metric DAbsorbedDose a rad = mkUnitQ (ucumMetric "RAD" "RAD" "RAD") 1 $ centi gray @@ -668,10 +715,10 @@ -- See <https://en.wikipedia.org/wiki/Viscosity#Kinematic_viscosity_.CE.BD here> for further information. -- -- >>> 1 *~ stokes--- 1.0e-4 m^2 s^-1+-- 1.0e-4 m^2 s^-1 -- -- >>> 1 *~ stokes :: KinematicViscosity Rational--- 1 % 10000 m^2 s^-1+-- 1 % 10000 m^2 s^-1 stokes :: (Fractional a) => Unit 'Metric DKinematicViscosity a stokes = mkUnitQ (ucumMetric "St" "St" "Stokes") 1 $ centi meter ^ pos2 / second @@ -687,10 +734,10 @@ -- See <https://en.wikipedia.org/wiki/Fahrenheit#Definition_and_conversions here> for further information. -- -- >>> 1 *~ degreeFahrenheit--- 0.5555555555555556 K+-- 0.5555555555555556 K -- -- >>> 1 *~ degreeFahrenheit :: ThermodynamicTemperature Rational--- 5 % 9 K+-- 5 % 9 K degreeFahrenheit :: (Fractional a) => Unit 'NonMetric DThermodynamicTemperature a degreeFahrenheit = mkUnitQ (ucum "[degF]" "°F" "degree Fahrenheit") (5 Prelude./ 9) $ degreeCelsius @@ -702,15 +749,15 @@ -- See <https://en.wikipedia.org/wiki/Rankine_scale here> for further information. -- -- >>> 1 *~ degreeRankine--- 0.5555555555555556 K+-- 0.5555555555555556 K -- -- >>> 1 *~ degreeRankine :: ThermodynamicTemperature Rational--- 5 % 9 K+-- 5 % 9 K degreeRankine :: (Fractional a) => Unit 'NonMetric DThermodynamicTemperature a degreeRankine = mkUnitQ (ucum "[degR]" "°R" "degree Rankine") 1 $ degreeFahrenheit  {- $imperial-volumes-Per http://en.wikipedia.org/wiki/Imperial_units and http://en.wikipedia.org/wiki/Cup_(unit)#Imperial_cup.+Per https://en.wikipedia.org/wiki/Imperial_units and https://en.wikipedia.org/wiki/Cup_(unit)#Imperial_cup. -}  -- | One imperial gallon is defined exactly in terms of the 'liter'@@ -719,10 +766,10 @@ -- See <https://en.wikipedia.org/wiki/Imperial_units#Volume here> for further information. -- -- >>> 1 *~ imperialGallon--- 4.54609e-3 m^3+-- 4.54609e-3 m^3 -- -- >>> 1 *~ imperialGallon :: Volume Rational--- 454609 % 100000000 m^3+-- 454609 % 100000000 m^3 imperialGallon :: (Fractional a) => Unit 'NonMetric DVolume a imperialGallon = mkUnitQ (ucum "[gal_br]" "gal" "gallon") 4.54609 $ liter @@ -731,10 +778,10 @@ -- See <https://en.wikipedia.org/wiki/Imperial_units#Volume here> for further information. -- -- >>> 1 *~ imperialQuart--- 1.1365225e-3 m^3+-- 1.1365225e-3 m^3 -- -- >>> 1 *~ imperialQuart :: Volume Rational--- 454609 % 400000000 m^3+-- 454609 % 400000000 m^3 imperialQuart :: (Fractional a) => Unit 'NonMetric DVolume a imperialQuart = mkUnitQ (ucum "[qt_br]" "qt" "quart") (1 Prelude./ 4) $ imperialGallon @@ -743,10 +790,10 @@ -- See <https://en.wikipedia.org/wiki/Imperial_units#Volume here> for further information. -- -- >>> 1 *~ imperialPint--- 5.6826125e-4 m^3+-- 5.6826125e-4 m^3 -- -- >>> 1 *~ imperialPint :: Volume Rational--- 454609 % 800000000 m^3+-- 454609 % 800000000 m^3 imperialPint :: (Fractional a) => Unit 'NonMetric DVolume a imperialPint = mkUnitQ (ucum "[pt_br]" "pt" "pint") (1 Prelude./ 8) $ imperialGallon @@ -758,10 +805,10 @@ -- See <https://en.wikipedia.org/wiki/Cup_%28unit%29#Imperial_cup here> for further information. -- -- >>> 1 *~ imperialCup--- 2.84130625e-4 m^3+-- 2.84130625e-4 m^3 -- -- >>> 1 *~ imperialCup :: Volume Rational--- 454609 % 1600000000 m^3+-- 454609 % 1600000000 m^3 imperialCup :: (Fractional a) => Unit 'NonMetric DVolume a imperialCup = mkUnitQ (dimensionalAtom "[cup_br]" "cup" "cup") 0.5 $ imperialPint @@ -770,10 +817,10 @@ -- See <https://en.wikipedia.org/wiki/Imperial_units#Volume here> for further information. -- -- >>> 1 *~ imperialGill--- 1.420653125e-4 m^3+-- 1.420653125e-4 m^3 -- -- >>> 1 *~ imperialGill :: Volume Rational--- 454609 % 3200000000 m^3+-- 454609 % 3200000000 m^3 imperialGill :: (Fractional a) => Unit 'NonMetric DVolume a imperialGill = mkUnitQ (ucum "[gil_br]" "gill" "gill") (1 Prelude./ 4) $ imperialPint @@ -782,15 +829,15 @@ -- See <https://en.wikipedia.org/wiki/Imperial_units#Volume here> for further information. -- -- >>> 1 *~ imperialFluidOunce--- 2.84130625e-5 m^3+-- 2.84130625e-5 m^3 -- -- >>> 1 *~ imperialFluidOunce :: Volume Rational--- 454609 % 16000000000 m^3+-- 454609 % 16000000000 m^3 imperialFluidOunce :: (Fractional a) => Unit 'NonMetric DVolume a imperialFluidOunce = mkUnitQ (ucum "[foz_br]" "fl oz" "fluid ounce") (1 Prelude./ 20) $ imperialPint  {- $us-customary-volumes-Per http://www.nist.gov/pml/wmd/pubs/upload/2012-hb44-final.pdf page 452 and http://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume+Per https://www.nist.gov/system/files/documents/2017/05/09/2012-hb44-final.pdf page 452 and https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume Note that there exist rarely-used "dry" variants of units with overlapping names. -} @@ -799,22 +846,22 @@ -- See <https://en.wikipedia.org/wiki/Gallon#The_US_liquid_gallon here> for further information. -- -- >>> 1 *~ usGallon--- 3.785411784e-3 m^3+-- 3.785411784e-3 m^3 -- -- >>> 1 *~ usGallon :: Volume Rational--- 473176473 % 125000000000 m^3+-- 473176473 % 125000000000 m^3 usGallon :: (Fractional a) => Unit 'NonMetric DVolume a-usGallon = mkUnitQ (ucum "[gal_us]" "gal" "gallon") 231 $ (cubic inch)+usGallon = mkUnitQ (ucum "[gal_us]" "gal" "gallon") 231 $ cubic inch  -- | One US liquid quart is one quarter of a 'usGallon'. -- -- See <https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume here> for further information. -- -- >>> 1 *~ usQuart--- 9.46352946e-4 m^3+-- 9.46352946e-4 m^3 -- -- >>> 1 *~ usQuart :: Volume Rational--- 473176473 % 500000000000 m^3+-- 473176473 % 500000000000 m^3 usQuart :: (Fractional a) => Unit 'NonMetric DVolume a usQuart = mkUnitQ (ucum "[qt_us]" "qt" "quart") (1 Prelude./ 4) $ usGallon @@ -823,10 +870,10 @@ -- See <https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume here> for further information. -- -- >>> 1 *~ usPint--- 4.73176473e-4 m^3+-- 4.73176473e-4 m^3 -- -- >>> 1 *~ usPint :: Volume Rational--- 473176473 % 1000000000000 m^3+-- 473176473 % 1000000000000 m^3 usPint :: (Fractional a) => Unit 'NonMetric DVolume a usPint = mkUnitQ (ucum "[pt_us]" "pt" "pint") (1 Prelude./ 8) $ usGallon @@ -835,10 +882,10 @@ -- See <https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume here> for further information. -- -- >>> 1 *~ usCup--- 2.365882365e-4 m^3+-- 2.365882365e-4 m^3 -- -- >>> 1 *~ usCup :: Volume Rational--- 473176473 % 2000000000000 m^3+-- 473176473 % 2000000000000 m^3 usCup :: (Fractional a) => Unit 'NonMetric DVolume a usCup = mkUnitQ (ucum "[cup_us]" "cup" "cup") (1 Prelude./ 2) $ usPint @@ -847,10 +894,10 @@ -- See <https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume here> for further information. -- -- >>> 1 *~ usGill--- 1.1829411825e-4 m^3+-- 1.1829411825e-4 m^3 -- -- >>> 1 *~ usGill :: Volume Rational--- 473176473 % 4000000000000 m^3+-- 473176473 % 4000000000000 m^3 usGill :: (Fractional a) => Unit 'NonMetric DVolume a usGill = mkUnitQ (ucum "[gil_us]" "gill" "gill") (1 Prelude./ 4) $ usPint @@ -859,10 +906,10 @@ -- See <https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume here> for further information. -- -- >>> 1 *~ usFluidOunce--- 2.95735295625e-5 m^3+-- 2.95735295625e-5 m^3 -- -- >>> 1 *~ usFluidOunce :: Volume Rational--- 473176473 % 16000000000000 m^3+-- 473176473 % 16000000000000 m^3 usFluidOunce :: (Fractional a) => Unit 'NonMetric DVolume a usFluidOunce = mkUnitQ (ucum "[foz_us]" "fl oz" "fluid ounce") (1 Prelude./ 16) $ usPint -- sic, does not match factor used in imperial system @@ -871,10 +918,10 @@ -- See <https://en.wikipedia.org/wiki/%C3%85ngstr%C3%B6m here> for further information. -- -- >>> 1 *~ angstrom--- 1.0e-10 m+-- 1.0e-10 m -- -- >>> 1 *~ angstrom :: Length Rational--- 1 % 10000000000 m+-- 1 % 10000000000 m angstrom :: (Fractional a) => Unit 'NonMetric DLength a angstrom = mkUnitQ (ucum "Ao" "Å" "Ångström") 0.1 $ nano meter @@ -883,9 +930,9 @@ -- See <https://en.wikipedia.org/wiki/Gauss_%28unit%29 here> for further information. -- -- >>> 1 *~ gauss--- 1.0e-4 kg s^-2 A^-1+-- 1.0e-4 kg s^-2 A^-1 -- -- >>> 1 *~ gauss :: MagneticFluxDensity Rational--- 1 % 10000 kg s^-2 A^-1+-- 1 % 10000 kg s^-2 A^-1 gauss :: (Fractional a) => Unit 'NonMetric DMagneticFluxDensity a gauss = mkUnitQ (ucum "G" "G" "Gauss") 1e-4 $ tesla
src/Numeric/Units/Dimensional/Quantities.hs view
@@ -20,11 +20,11 @@ for the dimensionality is defined first in terms of base dimension exponents. Then a type synonym for the corresponding quantity type is defined. If there are several quantity types with the same-dimensionality type synonyms are provided for each quantity type.+dimensionality, type synonyms are provided for each quantity type.  = References -1. #note1# http://physics.nist.gov/Pubs/SP811/+1. #note1# https://www.nist.gov/pml/special-publication-811  -} @@ -373,7 +373,7 @@  {- -Thermal conductance and resistance quantities after http://en.wikipedia.org/wiki/Thermal_conductivity#Definitions.+Thermal conductance and resistance quantities after https://en.wikipedia.org/wiki/Thermal_conductivity#Definitions.  -} @@ -418,6 +418,7 @@ -}  -- $setup+-- >>> :set -fno-warn-type-defaults -- >>> import Numeric.Units.Dimensional.Prelude  -- | Constructs a unit of area from a unit of length, taking the area of a square whose sides are that length.
src/Numeric/Units/Dimensional/SIUnits.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE DataKinds #-}-{-# LANGUAGE NumDecimals #-} {-# LANGUAGE RankNTypes #-}  {- |@@ -19,9 +18,9 @@  = References -1. #note1# http://physics.nist.gov/Pubs/SP811/-2. #note2# http://en.wikipedia.org/wiki/Minute_of_arc-3. #note3# http://en.wikipedia.org/wiki/Astronomical_unit+1. #note1# https://www.nist.gov/pml/special-publication-811+2. #note2# https://en.wikipedia.org/wiki/Minute_of_arc+3. #note3# https://en.wikipedia.org/wiki/Astronomical_unit  -} @@ -53,9 +52,9 @@   astronomicalUnit,   -- * SI Prefixes   -- $multiples-  deka, deca, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta,+  deka, deca, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta, ronna, quetta,   -- $submultiples-  deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto,+  deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto, ronto, quecto,   -- $reified-prefixes   Prefix, applyPrefix, siPrefixes )@@ -74,9 +73,7 @@  {- $multiples Prefixes are used to form decimal multiples and submultiples of SI-Units as described in section 4.4. We will define the SI prefixes-in terms of the 'prefix' function which applies a scale factor to a-unit.+Units as described in section 4.4.  By defining SI prefixes as functions applied to a 'Unit' we satisfy section 6.2.6 "Unacceptability of stand-alone prefixes".@@ -91,43 +88,75 @@     n' = N.applyPrefix p (name u)     x = N.scaleFactor p -deka, deca, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta+deca, deka, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta, ronna, quetta   :: Num a => Unit 'Metric d a -> Unit 'NonMetric d a-deka  = applyMultiple I.deka -- International English.-deca  = deka      -- American English.+-- | The "deca" prefix, denoting a factor of 10.+deca  = applyMultiple I.deca -- International English.+-- | An alias for 'deca'.+deka  = deca      -- American English.+-- | The "hecto" prefix, denoting a factor of 100. hecto = applyMultiple I.hecto+-- | The "kilo" prefix, denoting a factor of 1000. kilo  = applyMultiple I.kilo+-- | The "mega" prefix, denoting a factor of 10^6. mega  = applyMultiple I.mega+-- | The "giga" prefix, denoting a factor of 10^9. giga  = applyMultiple I.giga+-- | The "tera" prefix, denoting a factor of 10^12. tera  = applyMultiple I.tera+-- | The "peta" prefix, denoting a factor of 10^15. peta  = applyMultiple I.peta+-- | The "exa" prefix, denoting a factor of 10^18. exa   = applyMultiple I.exa+-- | The "zetta" prefix, denoting a factor of 10^21. zetta = applyMultiple I.zetta+-- | The "yotta" prefix, denoting a factor of 10^24. yotta = applyMultiple I.yotta+-- | The "ronna" prefix, denoting a factor of 10^27.+ronna = applyMultiple I.ronna+-- | The "quetta" prefix, denoting a factor of 10^30.+quetta = applyMultiple I.quetta + {- $submultiples Then the submultiples. -} +-- | Apply a 'Prefix' to a metric 'Unit'. applyPrefix :: (Fractional a) => Prefix -> Unit 'Metric d a -> Unit 'NonMetric d a applyPrefix p u = mkUnitQ n' x u   where     n' = N.applyPrefix p (name u)     x = N.scaleFactor p -deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto+deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto, ronto, quecto   :: Fractional a => Unit 'Metric d a -> Unit 'NonMetric d a+-- | The "deci" prefix, denoting a factor of 0.1. deci  = applyPrefix I.deci+-- | The "centi" prefix, denoting a factor of 0.01. centi = applyPrefix I.centi+-- | The "milli" prefix, denoting a factor of 0.001. milli = applyPrefix I.milli+-- | The "micro" prefix, denoting a factor of 10^-6. micro = applyPrefix I.micro+-- | The "nano" prefix, denoting a factor of 10^-9. nano  = applyPrefix I.nano+-- | The "pico" prefix, denoting a factor of 10^-12. pico  = applyPrefix I.pico+-- | The "femto" prefix, denoting a factor of 10^-15. femto = applyPrefix I.femto+-- | The "atto" prefix, denoting a factor of 10^-18. atto  = applyPrefix I.atto+-- | The "zepto" prefix, denoting a factor of 10^-21. zepto = applyPrefix I.zepto+-- | The "yocto" prefix, denoting a factor of 10^-24. yocto = applyPrefix I.yocto+-- | The "ronto" prefix, denoting a factor of 10^-27.+ronto = applyPrefix I.ronto+-- | The "quecto" prefix, denoting a factor of 10^-30.+quecto = applyPrefix I.quecto + {- $reified-prefixes  We supply an explicit representation of an SI prefix, along with a function to apply one and a@@ -138,7 +167,7 @@ {- $base-units These are the base units from section 4.1. To avoid a myriad of one-letter functions that would doubtlessly cause clashes-and frustration in users' code we spell out all unit names in full,+and frustration in users' code, we spell out all unit names in full, as we did for prefixes. We also elect to spell the unit names in singular form, as allowed by section 9.7 "Other spelling conventions". @@ -312,4 +341,4 @@ -}  astronomicalUnit :: Num a => Unit 'NonMetric DLength a-astronomicalUnit = mkUnitZ (ucum "AU" "AU" "astronomical unit") 149597870700 $ meter+astronomicalUnit = mkUnitZ (ucum "au" "au" "astronomical unit") 149597870700 $ meter
src/Numeric/Units/Dimensional/UnitNames/InterchangeNames.hs view
@@ -9,7 +9,7 @@ ) where -import Control.DeepSeq+import Control.DeepSeq (NFData) import Data.Data import GHC.Generics import Prelude
src/Numeric/Units/Dimensional/UnitNames/Internal.hs view
@@ -1,7 +1,5 @@ {-# OPTIONS_HADDOCK not-home #-} -{-# LANGUAGE AutoDeriveTypeable #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}@@ -16,15 +14,11 @@ module Numeric.Units.Dimensional.UnitNames.Internal where -import Control.DeepSeq+import Control.DeepSeq (NFData(..)) import Control.Monad (join) import Data.Coerce import Data.Data hiding (Prefix)-#if MIN_VERSION_base(4, 8, 0) import Data.Foldable (toList)-#else-import Data.Foldable (Foldable, toList)-#endif import Data.Ord import GHC.Generics hiding (Prefix) import Numeric.Units.Dimensional.Dimensions.TermLevel (Dimension', asList, HasDimension(..))@@ -36,23 +30,23 @@  -- | The name of a unit. data UnitName (m :: Metricality) where-  -- The name of the unit of dimensionless values.+  -- | The name of the unit of dimensionless values.   One :: UnitName 'NonMetric-  -- A name of an atomic unit to which metric prefixes may be applied.+  -- | A name of an atomic unit to which metric prefixes may be applied.   MetricAtomic :: NameAtom ('UnitAtom 'Metric) -> UnitName 'Metric-  -- A name of an atomic unit to which metric prefixes may not be applied.+  -- | A name of an atomic unit to which metric prefixes may not be applied.   Atomic :: NameAtom ('UnitAtom 'NonMetric) -> UnitName 'NonMetric-  -- A name of a prefixed unit.+  -- | A name of a prefixed unit.   Prefixed :: PrefixName -> UnitName 'Metric -> UnitName 'NonMetric-  -- A compound name formed from the product of two names.+  -- | A compound name formed from the product of two names.   Product :: UnitName 'NonMetric -> UnitName 'NonMetric -> UnitName 'NonMetric-  -- A compound name formed from the quotient of two names.+  -- | A compound name formed from the quotient of two names.   Quotient :: UnitName 'NonMetric -> UnitName 'NonMetric -> UnitName 'NonMetric-  -- A compound name formed by raising a unit name to an integer power.+  -- | A compound name formed by raising a unit name to an integer power.   Power :: UnitName 'NonMetric -> Int -> UnitName 'NonMetric-  -- A compound name formed by grouping another name, which is generally compound.+  -- | A compound name formed by grouping another name, which is generally compound.   Grouped :: UnitName 'NonMetric -> UnitName 'NonMetric-  -- A weakened name formed by forgetting that it could accept a metric prefix.+  -- | A weakened name formed by forgetting that it could accept a metric prefix.   --   -- Also available is the smart constructor `weaken` which accepts any `UnitName` as input.   Weaken :: UnitName 'Metric -> UnitName 'NonMetric@@ -73,25 +67,28 @@     Grouped n' -> rnf n'     Weaken n' -> rnf n' +-- | `UnitName`s are shown with non-breaking spaces. instance Show (UnitName m) where   show One = "1"   show (MetricAtomic a) = abbreviation_en a   show (Atomic a) = abbreviation_en a   show (Prefixed a n) = abbreviation_en a ++ show n-  show (Product n1 n2) = show n1 ++ " " ++ show n2-  show (Quotient n1 n2) = show n1 ++ " / " ++ show n2+  show (Product n1 n2) = show n1 ++ "\xA0" ++ show n2+  show (Quotient n1 n2) = show n1 ++ "\xA0/\xA0" ++ show n2   show (Power x n) = show x ++ "^" ++ show n   show (Grouped n) = "(" ++ show n ++ ")"   show (Weaken n) = show n +-- | Converts a 'UnitName' to a 'NameAtom', if possible. asAtomic :: UnitName m -> Maybe (NameAtom ('UnitAtom m)) asAtomic (MetricAtomic a) = Just a asAtomic (Atomic a) = Just a-asAtomic (Weaken n) = fmap coerce $ asAtomic n+asAtomic (Weaken n) = coerce <$> asAtomic n asAtomic _ = Nothing +-- | Returns 'True' if the 'UnitName' is atomic. isAtomic :: UnitName m -> Bool-isAtomic (One) = True+isAtomic One = True isAtomic (MetricAtomic _) = True isAtomic (Atomic _) = True isAtomic (Prefixed _ _) = True@@ -103,15 +100,15 @@ isAtomicOrProduct (Product _ _) = True isAtomicOrProduct n = isAtomic n --- reduce by algebraic simplifications+-- | Reduce a 'UnitName' by algebraic simplifications. reduce :: UnitName m -> UnitName m-reduce (One) = One+reduce One = One reduce n@(MetricAtomic _) = n reduce n@(Atomic _) = n reduce n@(Prefixed _ _) = n reduce (Product n1 n2) = reduce' (reduce n1 * reduce n2) reduce (Quotient n1 n2) = reduce' (reduce n1 * reduce n2)-reduce (Power n x) = reduce' ((reduce n) ^ x)+reduce (Power n x) = reduce' (reduce n ^ x) reduce (Grouped n) = reduce' (Grouped (reduce n)) reduce (Weaken n) = reduce' (Weaken (reduce n)) @@ -136,6 +133,7 @@ -- | The name of a metric prefix. type PrefixName = NameAtom 'PrefixAtom +-- | A metric prefix. data Prefix = Prefix               {                 -- | The name of a metric prefix.@@ -189,8 +187,8 @@ baseUnitNames :: [UnitName 'NonMetric] baseUnitNames = [weaken nMeter, nKilogram, weaken nSecond, weaken nAmpere, weaken nKelvin, weaken nMole, weaken nCandela] -deka, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta :: Prefix-deka  = prefix "da" "da" "deka" 1e1+deca, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta, ronna, quetta :: Prefix+deca  = prefix "da" "da" "deca" 1e1 hecto = prefix "h" "h" "hecto"  1e2 kilo  = prefix "k" "k" "kilo"   1e3 mega  = prefix "M" "M" "mega"   1e6@@ -200,7 +198,10 @@ exa   = prefix "E" "E" "exa"    1e18 zetta = prefix "Z" "Z" "zetta"  1e21 yotta = prefix "Y" "Y" "yotta"  1e24-deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto :: Prefix+ronna = prefix "R" "R" "ronna" 1e27+quetta = prefix "Q" "Q" "quetta" 1e30++deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto, ronto, quecto :: Prefix deci  = prefix "d" "d" "deci"   1e-1 centi = prefix "c" "c" "centi"  1e-2 milli = prefix "m" "m" "milli"  1e-3@@ -211,10 +212,13 @@ atto  = prefix "a" "a" "atto"   1e-18 zepto = prefix "z" "z" "zepto"  1e-21 yocto = prefix "y" "y" "yocto"  1e-24+ronto = prefix "r" "r" "ronto"  1e-27+quecto = prefix "q" "q" "quecto"  1e-30 + -- | A list of all 'Prefix'es defined by the SI. siPrefixes :: [Prefix]-siPrefixes = [yocto, zepto, atto, femto, pico, nano, micro, milli, centi, deci, deka, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta]+siPrefixes = [quecto, ronto, yocto, zepto, atto, femto, pico, nano, micro, milli, centi, deci, deca, hecto, kilo, mega, giga, tera, peta, exa, zetta, yotta, ronna, quetta]  -- | Forms a 'UnitName' from a 'Metric' name by applying a metric prefix. applyPrefix :: Prefix -> UnitName 'Metric -> UnitName 'NonMetric@@ -267,7 +271,7 @@ -- strengthening or weakening if neccessary. Because it may not be possible to strengthen, -- the result is returned in a 'Maybe' wrapper. relax :: forall m1 m2.(Typeable m1, Typeable m2) => UnitName m1 -> Maybe (UnitName m2)-relax n = go (typeRep (Proxy :: Proxy m1)) (typeRep (Proxy :: Proxy m2)) n+relax = go (typeRep (Proxy :: Proxy m1)) (typeRep (Proxy :: Proxy m2))   where     metric = typeRep (Proxy :: Proxy 'Metric)     nonMetric = typeRep (Proxy :: Proxy 'NonMetric)@@ -287,8 +291,8 @@   = NameAtom   {     _interchangeName :: InterchangeName, -- ^ The interchange name of the unit.-    abbreviation_en :: String, -- ^ The abbreviated name of the unit in international English-    name_en :: String -- ^ The full name of the unit in international English+    abbreviation_en :: String, -- ^ The abbreviated name of the unit in international English.+    name_en :: String -- ^ The full name of the unit in international English.   }   deriving (Eq, Ord, Data, Typeable, Generic) @@ -313,14 +317,14 @@   -- TODO #109: note in this case that the UCUM is changing their grammar to not accept exponents after   -- as a result it will become necessary to distribute the exponentiation over the items in the base name   -- prior to generating the interchange name-  interchangeName (Power n x) = let n' = (name . interchangeName $ n) ++ (show x)+  interchangeName (Power n x) = let n' = (name . interchangeName $ n) ++ show x                                  in InterchangeName { name = n', authority = authority . interchangeName $ n, I.isAtomic = False }   interchangeName (Grouped n) = let n' = "(" ++ (name . interchangeName $ n) ++ ")"                                  in InterchangeName { name = n', authority = authority . interchangeName $ n, I.isAtomic = False }   interchangeName (Weaken n) = interchangeName n  prefix :: String -> String -> String -> Rational -> Prefix-prefix i a f q = Prefix n q+prefix i a f = Prefix n   where     n = NameAtom (InterchangeName i UCUM True) a f 
src/Numeric/Units/Dimensional/Variants.hs view
@@ -1,6 +1,5 @@ {-# OPTIONS_HADDOCK not-home, show-extensions #-} -{-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-}@@ -29,7 +28,7 @@ ) where -import Control.DeepSeq+import Control.DeepSeq (NFData) import Data.Data import qualified Data.ExactPi.TypeLevel as E import GHC.Generics@@ -72,6 +71,11 @@   'DUnit m1 * 'DUnit m2 = 'DUnit 'NonMetric   'DQuantity s1 * 'DQuantity s2 = 'DQuantity (s1 E.* s2) +-- | Forms the quotient of two 'Variant's.+--+-- The quotient of units is a non-metric unit.+--+-- The quotient of quantities is a quantity. type family (v1 :: Variant) / (v2 :: Variant) :: Variant where   'DUnit m1 / 'DUnit m2 = 'DUnit 'NonMetric   'DQuantity s1 / 'DQuantity s2 = 'DQuantity (s1 E./ s2)@@ -84,8 +88,8 @@ -- | Two 'Variant's are compatible when dimensional values of the first may be converted -- into the second merely by changing the representation of their values. type family AreCompatible (v1 :: Variant) (v2 :: Variant) :: Bool where-  AreCompatible ('DQuantity s1)  ('DQuantity s2) = 'True-  AreCompatible ('DUnit m) ('DUnit 'NonMetric)   = 'True+  AreCompatible ('DQuantity s1) ('DQuantity s2) = 'True+  AreCompatible ('DUnit m) ('DUnit 'NonMetric)  = 'True   AreCompatible s s   = 'True   AreCompatible s1 s2 = 'False 
− tests/DocTests.hs
@@ -1,10 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeSynonymInstances #-}--module Main (main) where--import System.FilePath.Glob (glob)-import Test.DocTest (doctest)--main :: IO ()-main = glob "src/**/*.hs" >>= doctest
tests/Numeric/Units/DimensionalSpec.hs view
@@ -17,10 +17,11 @@           describe "Show instance" $ do            it "properly prints basic quantities" $ do+             -- note: these comparison literals use non-breaking spaces              show ((1.0::Double) *~ one) `shouldBe` "1.0"-             show ((2.0::Double) *~ meter) `shouldBe` "2.0 m"-             show ((2.0::Double) *~ (meter / second)) `shouldBe` "2.0 m s^-1"-             show ((2.0::Double) *~ (meter ^ pos2 / second ^ pos2)) `shouldBe` "2.0 m^2 s^-2"+             show ((2.0::Double) *~ meter) `shouldBe` "2.0 m"+             show ((2.0::Double) *~ (meter / second)) `shouldBe` "2.0 m s^-1"+             show ((2.0::Double) *~ (meter ^ pos2 / second ^ pos2)) `shouldBe` "2.0 m^2 s^-2"           describe "Ord instance" $ do            it "properly sorts quantities" $ do
tests/Spec.hs view
@@ -1,4 +1,4 @@ {-# OPTIONS_GHC -F -pgmF hspec-discover #-}  -- This module will automatically pull in all the Spec modules.--- See http://hspec.github.io/hspec-discover.html for a summary of how it works.+-- See https://hspec.github.io/hspec-discover.html for a summary of how it works.