packages feed

units 2.3 → 2.4.1.5

raw patch · 69 files changed

Files

CHANGES.md view
@@ -1,6 +1,44 @@ Release notes for `units` ========================= +Version 2.4.1.5+---------------+* Use the `(-)` operator of the underlying `Num` instance in `(|-|)`.+  This prevents crashes when the underlying number type does not support+  negation. (Issue #69)+* Compatibility with GHC 9.2.++Version 2.4.1.4+---------------+* Compatibility with GHC 9.0.++Version 2.4.1.3+---------------+* Compatibility with GHC 8.10, thanks to @ocharles.++Version 2.4.1.2+---------------+* Compatibility with singletons 2.6 and GHC 8.8, further thanks to @ocharles.++Version 2.4.1.1+---------------+* Fix some GHC compatibility issues, thanks to @ocharles.++Version 2.4.1+-------------+* Add `Units` superclass to `UnitFactor`, easing type inference in+GHC 8.0, thanks to @rimmington.++Version 2.4+-----------+* New interface with the `linear` package in `Data.Metrology.Linear`.++* New `Show` and `Read` instances for dimensionless quantities.++* New `NFData` instances for quantities, thanks to @rimmington.++* GHC 8 compatibility.+ Version 2.3 ----------- * `Data.Metrology.TH.evalType` now works in GHC 7.10 on dimensions like `Volume` instead
Data/Metrology.hs view
@@ -2,7 +2,7 @@     The units Package    Copyright (c) 2014 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file gathers and exports all user-visible pieces of the units package.    It also defines the main creators and consumers of dimensioned objects.@@ -26,7 +26,7 @@ -- Module      :  Data.Metrology -- Copyright   :  (C) 2014 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -37,7 +37,7 @@ -- -- Some of the types below refer to declarations that are not exported and -- not documented here. This is because Haddock does not allow finely-tuned--- abstraction in documentation. (In particular, right-hand sides of type +-- abstraction in documentation. (In particular, right-hand sides of type -- synonym declarations are always included.) If a symbol is not exported, -- you do /not/ need to know anything about it to use this package. --@@ -74,7 +74,7 @@ -- --   or -----   > inMeters x = x # Meter   +--   > inMeters x = x # Meter numIn :: ( ValidDLU dim DefaultLCSU unit          , Fractional n )       => Qu dim DefaultLCSU n -> unit -> n
Data/Metrology/Combinators.hs view
@@ -2,14 +2,18 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file defines combinators to build more complex units and dimensions from simpler ones. -} -{-# LANGUAGE TypeOperators, TypeFamilies, UndecidableInstances, +{-# LANGUAGE TypeOperators, TypeFamilies, UndecidableInstances,              ScopedTypeVariables, DataKinds, FlexibleInstances,-             ConstraintKinds #-}+             ConstraintKinds, CPP #-}++#if __GLASGOW_HASKELL__ >= 711+{-# OPTIONS_GHC -Wno-redundant-constraints #-}+#endif  module Data.Metrology.Combinators where 
Data/Metrology/Dimensions.hs view
@@ -2,7 +2,7 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file defines the class Dimension, which is needed for    defining dimensions.@@ -10,8 +10,12 @@  {-# LANGUAGE TypeFamilies, DataKinds, DefaultSignatures, MultiParamTypeClasses,              ConstraintKinds, UndecidableInstances, FlexibleContexts,-             FlexibleInstances, ScopedTypeVariables, TypeOperators #-}+             FlexibleInstances, ScopedTypeVariables, TypeOperators, CPP #-} +#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ module Data.Metrology.Dimensions where  import Data.Metrology.Z@@ -24,4 +28,3 @@   -- the default of this type family should not be necessary in user code.   type DimFactorsOf dim :: [Factor *]   type DimFactorsOf dim = '[F dim One]-  
Data/Metrology/Factor.hs view
@@ -2,23 +2,36 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file defines the Factor kind and operations over lists of Factors.     Factors represents dimensions and units raised to a power of integers, and the lists of Factors represents monomials of dimensions and units. -} -{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, UndecidableInstances #-}+{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, UndecidableInstances, CPP #-} +-- allow compilation even without Cabal+#ifndef MIN_VERSION_singletons+#define MIN_VERSION_singletons(a,b,c) 1+#endif++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ module Data.Metrology.Factor where  import GHC.Exts (Constraint) import Data.Metrology.Z as Z-import Data.Type.Equality+import Data.Type.Equality as DTE import Data.Type.Bool +#if MIN_VERSION_singletons(3,0,0)+import Prelude.Singletons+#else import Data.Singletons.Prelude+#endif  -- | This will only be used at the kind level. It holds a dimension or unit -- with its exponent.@@ -55,7 +68,7 @@ infix 4 $= -- | Do these Factors represent the same dimension? type family (a :: Factor *) $= (b :: Factor *) :: Bool where-  (F n1 z1) $= (F n2 z2) = n1 == n2+  (F n1 z1) $= (F n2 z2) = n1 DTE.== n2   a         $= b         = False  -- | @(Extract s lst)@ pulls the Factor that matches s out of lst, returning a
Data/Metrology/Internal.hs view
@@ -2,7 +2,7 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file gathers and exports user-visible type-level definitions, to    make error messages less cluttered. Non-expert users should never have@@ -14,7 +14,7 @@ -- Module      :  Data.Metrology.Internal -- Copyright   :  (C) 2013 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -54,5 +54,3 @@ import Data.Metrology.Factor import Data.Metrology.Set import Data.Metrology.Dimensions--  
Data/Metrology/LCSU.hs view
@@ -2,15 +2,20 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     Defines a locally coherent system of units (LCSUs),    implemented as an association list.-   An LCSU is a from base dimensions to units, thus +   An LCSU is a from base dimensions to units, thus    defining a uniquely mapping units for any dimensions. -} -{-# LANGUAGE DataKinds, PolyKinds, TypeFamilies, TypeOperators, UndecidableInstances #-}+{-# LANGUAGE DataKinds, PolyKinds, TypeFamilies, TypeOperators, UndecidableInstances,+             CPP #-}++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif  module Data.Metrology.LCSU (   LCSU(DefaultLCSU), DefaultUnitOfDim,
+ Data/Metrology/Linear.hs view
@@ -0,0 +1,319 @@+{-# LANGUAGE TypeOperators, FlexibleContexts, DataKinds, TypeFamilies,+             ScopedTypeVariables, ConstraintKinds, GeneralizedNewtypeDeriving,+             MultiParamTypeClasses, FlexibleInstances, InstanceSigs, CPP #-}++#if __GLASGOW_HASKELL__ >= 711+{-# OPTIONS_GHC -Wno-redundant-constraints #-}+#endif++-----------------------------------------------------------------------------+-- |+-- Module      :  Data.Metrology.Linear+-- Copyright   :  (C) 2014 Richard Eisenberg, (C) 2015 Tobias Markus+-- License     :  BSD-style (see LICENSE)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu)+-- Stability   :  experimental+-- Portability :  non-portable+--+-- Exports combinators for building quantities out of vectors, from the+-- @linear@ library.+------------------------------------------------------------------------------++module Data.Metrology.Linear (+  -- * Term-level combinators++  -- | The term-level arithmetic operators are defined by+  -- applying vertical bar(s) to the sides the dimensioned+  -- quantities acts on.++  -- ** Additive operations+  zeroV, (|^+^|), (|^-^|), qNegateV, qSumV,++  -- ** Multiplicative operations+  (|*^|), (|^*|), (|^/|), (*^|), (|^*), (|^/), (|.|),++  -- ** Vector-space operations+  qBasis, qBasisFor, qScaled, qOuter, qUnit,+  qQuadrance, qNorm, qSignorm, qProject, qCross,++  -- ** Affine operations+  (|.-.|), (|.+^|), (|.-^|), qQd, qDistance, qQdA, qDistanceA,++  -- * Nondimensional units, conversion between quantities and numeric values+  numInV, (^#), quOfV, (^%), showInV,+  convertV, constantV,++  ) where++import Data.Metrology.Qu+import Data.Metrology.LCSU+import Data.Metrology.Validity+import Data.Metrology.Factor+import Data.Metrology.Z as Z+import Data.Metrology.Units++import Linear+import Linear.Affine hiding (P)+import qualified Control.Lens as Lens++import Data.Proxy+import Data.Foldable    as F+#if __GLASGOW_HASKELL__ < 709+import Data.Traversable ( Traversable )+#endif++---------------------------------------+-- Additive operations+---------------------------------------++-- | The number 0, polymorphic in its dimension. Use of this will+-- often require a type annotation.+zeroV :: (Additive f, Num a) => Qu d l (f a)+zeroV = Qu Linear.zero++infixl 6 |^+^|+-- | Add two compatible vector quantities+(|^+^|) :: (d1 @~ d2, Additive f, Num a)+        => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l (f a)+(Qu a) |^+^| (Qu b) = Qu (a ^+^ b)++-- | Negate a vector quantity+qNegateV :: (Additive f, Num a) => Qu d l (f a) -> Qu d l (f a)+qNegateV (Qu x) = Qu (negated x)++infixl 6 |^-^|+-- | Subtract two compatible quantities+(|^-^|) :: (d1 @~ d2, Additive f, Num a)+        => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l (f a)+(Qu a) |^-^| (Qu b) = Qu (a ^-^ b)++-- | Take the sum of a list of quantities+qSumV :: (Foldable t, Additive f, Num a) => t (Qu d l (f a)) -> Qu d l (f a)+qSumV = F.foldr (|^+^|) zeroV++---------------------------------------+-- Multiplicative operations+---------------------------------------++infixl 7 |*^|, |^*|, |^/|+-- | Multiply a scalar quantity by a vector quantity+(|*^|) :: (Functor f, Num a)+       => Qu d1 l a -> Qu d2 l (f a) -> Qu (Normalize (d1 @+ d2)) l (f a)+(Qu a) |*^| (Qu b) = Qu (a *^ b)++-- | Multiply a vector quantity by a scalar quantity+(|^*|) :: (Functor f, Num a)+       => Qu d1 l (f a) -> Qu d2 l a -> Qu (Normalize (d1 @+ d2)) l (f a)+(Qu a) |^*| (Qu b) = Qu (a ^* b)++-- | Divide a vector quantity by a scalar quantity+(|^/|) :: (Functor f, Fractional a)+       => Qu d1 l (f a) -> Qu d2 l a -> Qu (Normalize (d1 @- d2)) l (f a)+(Qu a) |^/| (Qu b) = Qu (a ^/ b)++infixl 7 |^/+-- | Divide a quantity by a plain old number+(|^/) :: (Functor f, Fractional a) => Qu d l (f a) -> a -> Qu d l (f a)+(Qu a) |^/ b = Qu (a ^/ b)++infixl 7 *^| , |^*+-- | Multiply a quantity by a plain old number from the left+(*^|) :: (Functor f, Num a) => a -> Qu b l (f a) -> Qu b l (f a)+a *^| (Qu b) =  Qu (a *^ b)++-- | Multiply a quantity by a plain old number from the right+(|^*) :: (Functor f, Num a) => Qu b l (f a) -> a -> Qu b l (f a)+(Qu a) |^* b = Qu (a ^* b)++---------------------------------------+-- Vector-space operations+---------------------------------------++-- | Return a default basis, where each basis element measures 1 of the+-- unit provided.+qBasis :: ( ValidDLU dim lcsu unit+          , Additive f+          , Traversable f+          , Fractional a )+       => unit -> [Qu dim lcsu (f a)]+qBasis u = map (^% u) basis++-- | Return a default basis for the vector space provided. Each basis+-- element measures 1 of the unit provided.+qBasisFor :: ( ValidDLU dim lcsu unit+             , Additive f+             , Traversable f+             , Fractional a )+          => unit -> Qu dim lcsu (f b) -> [Qu dim lcsu (f a)]+qBasisFor u (Qu vec) = map (^% u) (basisFor vec)++-- | Produce a diagonal (scale) matrix from a vector+qScaled :: (Traversable f, Num a)+        => Qu dim lcsu (f a) -> Qu dim lcsu (f (f a))+qScaled (Qu vec) = Qu (scaled vec)++-- | Outer (tensor) product of two quantity vectors+qOuter :: (Functor f, Functor g, Num a)+       => Qu d1 l (f a) -> Qu d2 l (g a) -> Qu (Normalize (d1 @+ d2)) l (f (g a))+qOuter (Qu a) (Qu b) = Qu (a `outer` b)++-- | Create a unit vector from a setter and a choice of unit.+qUnit :: (ValidDLU dim lcsu unit, Additive t, Fractional a)+      => Lens.ASetter' (t a) a -> unit -> Qu dim lcsu (t a)+qUnit setter u = unit setter ^% u++infixl 7 |.|+-- | Take a inner (dot) product between two quantities.+(|.|) :: (Metric f, Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu (Normalize (d1 @+ d2)) l a+(Qu a) |.| (Qu b) = Qu (a `dot` b)++-- | Square the length of a vector.+qQuadrance :: (Metric f, Num a) => Qu d l (f a) -> Qu (d @* Z.Two) l a+qQuadrance (Qu x) = Qu (quadrance x)++-- | Length of a vector.+qNorm :: (Metric f, Floating a) => Qu d l (f a) -> Qu d l a+qNorm (Qu x) = Qu (norm x)++-- | Vector in same direction as given one but with length of one. If given the zero+-- vector, then return it. The returned vector is dimensionless.+qSignorm :: (Metric f, Floating a)+         => Qu d l (f a) -> Qu '[] l (f a)+qSignorm (Qu x) = Qu (signorm x)++-- | @qProject u v@ computes the projection of @v@ onto @u@.+qProject :: (Metric f, Fractional a)+         => Qu d2 l (f a) -> Qu d1 l (f a) -> Qu d1 l (f a)+qProject (Qu u) (Qu v) = Qu (u `project` v)++-- | Cross product of 3D vectors.+qCross :: Num a+       => Qu d1 l (V3 a) -> Qu d2 l (V3 a) -> Qu (Normalize (d1 @+ d2)) l (V3 a)+qCross (Qu x) (Qu y) = Qu (x `cross` y)++-- | Square of the distance between two vectors.+qQd :: (d1 @~ d2, Metric f, Metric (Diff f), Num a)+            => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu (d1 @* Z.Two) l a+qQd (Qu a) (Qu b) = Qu (a `qd` b)++-- | Distance between two vectors.+qDistance :: (d1 @~ d2, Metric f, Metric (Diff f), Floating a)+          => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l a+qDistance (Qu a) (Qu b) = Qu (a `distance` b)++---------------------------------------+-- Affine space operations+---------------------------------------++-- | Subtract point quantities.+(|.-.|) :: (d1 @~ d2, Affine f, Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l (Diff f a)+(Qu a) |.-.| (Qu b) = Qu (a .-. b)++-- | Add a point to a vector.+(|.+^|) :: (d1 @~ d2, Affine f, Num a) => Qu d1 l (f a) -> Qu d2 l (Diff f a) -> Qu d1 l (f a)+(Qu a) |.+^| (Qu b) = Qu (a .+^ b)++-- | Subract a vector from a point.+(|.-^|) :: (d1 @~ d2, Affine f, Num a) => Qu d1 l (f a) -> Qu d2 l (Diff f a) -> Qu d1 l (f a)+(Qu a) |.-^| (Qu b) = Qu (a .-^ b)++-- | Square of the distance between two points.+qQdA :: (d1 @~ d2, Affine f, Foldable (Diff f), Num a)+            => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu (d1 @* Z.Two) l a+qQdA (Qu a) (Qu b) = Qu (a `qdA` b)++-- | Distance between two points.+qDistanceA :: (d1 @~ d2, Affine f, Foldable (Diff f), Floating a)+          => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l a+qDistanceA (Qu a) (Qu b) = Qu (a `distanceA` b)++---------------------------------------+-- Top-level operations+---------------------------------------++-- | Extracts a numerical value from a dimensioned quantity, expressed in+--   the given unit. For example:+--+--   > inMeters :: Length -> Double+--   > inMeters x = numIn x Meter+--+--   or+--+--   > inMeters x = x # Meter+numInV :: forall unit dim lcsu f a.+         ( ValidDLU dim lcsu unit+         , Functor f+         , Fractional a )+      => Qu dim lcsu (f a) -> unit -> (f a)+numInV (Qu val) u+  = val ^* fromRational+             (canonicalConvRatioSpec (Proxy :: Proxy (LookupList dim lcsu))+              / canonicalConvRatio u)++infix 5 ^#+-- | Infix synonym for 'numIn'+(^#) :: ( ValidDLU dim lcsu unit+         , Functor f+         , Fractional a )+    => Qu dim lcsu (f a) -> unit -> (f a)+(^#) = numInV++-- | Creates a dimensioned quantity in the given unit. For example:+--+--   > height :: Length+--   > height = quOf 2.0 Meter+--+--   or+--+--   > height = 2.0 % Meter+quOfV :: forall unit dim lcsu f a.+         ( ValidDLU dim lcsu unit+         , Functor f+         , Fractional a )+      => (f a) -> unit -> Qu dim lcsu (f a)+quOfV d u+  = Qu (d ^* fromRational+               (canonicalConvRatio u+                / canonicalConvRatioSpec (Proxy :: Proxy (LookupList dim lcsu))))++infixr 9 ^%+-- | Infix synonym for 'quOf'+(^%) :: ( ValidDLU dim lcsu unit+         , Functor f+         , Fractional a )+    => (f a) -> unit -> Qu dim lcsu (f a)+(^%) = quOfV++-- | Dimension-keeping cast between different CSUs.+convertV :: forall d l1 l2 f a.+  ( ConvertibleLCSUs d l1 l2+  , Functor f+  , Fractional a )+  => Qu d l1 (f a) -> Qu d l2 (f a)+convertV (Qu x) = Qu $ x ^* fromRational (+  canonicalConvRatioSpec (Proxy :: Proxy (LookupList d l1))+  / canonicalConvRatioSpec (Proxy :: Proxy (LookupList d l2)))+++-- | Compute the argument in the @DefaultLCSU@, and present the result as+-- lcsu-polymorphic dimension-polymorphic value. Named 'constant' because one+-- of its dominant usecase is to inject constant quantities into+-- dimension-polymorphic expressions.+constantV :: ( d @~ e+            , ConvertibleLCSUs e DefaultLCSU l+            , Functor f+            , Fractional a )+         => Qu d DefaultLCSU (f a) -> Qu e l (f a)+constantV = convertV . redim++infix 1 `showInV`+-- | Show a dimensioned quantity in a given unit. (The default @Show@+-- instance always uses units as specified in the LCSU.)+showInV :: ( ValidDLU dim lcsu unit+          , Functor f+          , Fractional a+          , Show unit+          , Show a+          , Show (f a) )+       => Qu dim lcsu (f a) -> unit -> String+showInV x u = show (x ^# u) ++ " " ++ show u
Data/Metrology/Parser.hs view
@@ -3,7 +3,7 @@ -- Module      :  Data.Metrology.Parser -- Copyright   :  (C) 2014 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -50,7 +50,7 @@   makeQuasiQuoter, allUnits, allPrefixes,    -- * Direct interface-  +   -- | The definitions below allow users to access the unit parser directly.   -- The parser produces 'UnitExp's which can then be further processed as   -- necessary.@@ -153,7 +153,7 @@          , ValD (VarP qq_name) (NormalB qq) []]   where     qq_name = mkName qq_name_str-    +     mk_pair :: Name -> Q Exp   -- Exp is of type (String, Name)     mk_pair n = [| (show (undefined :: $( return $ ConT n )), n) |] @@ -172,7 +172,11 @@   ClassI _ insts <- reify class_name   m_names <- forM insts $ \inst ->     case inst of-      InstanceD _ ((ConT class_name') `AppT` (ConT unit_name)) []+      InstanceD+#if __GLASGOW_HASKELL__ >= 711+        _+#endif+          _ ((ConT class_name') `AppT` (ConT unit_name)) []         |  class_name == class_name'         -> do show_insts <- reifyInstances ''Show [ConT unit_name]               case show_insts of
Data/Metrology/Poly.hs view
@@ -2,7 +2,7 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file gathers and exports all user-visible pieces of the units package.    It also defines the main creators and consumers of dimensioned objects.@@ -10,14 +10,18 @@  {-# LANGUAGE ExplicitNamespaces, DataKinds, FlexibleInstances, TypeFamilies,              TypeOperators, ConstraintKinds, ScopedTypeVariables,-             FlexibleContexts, UndecidableInstances #-}+             FlexibleContexts, UndecidableInstances, CPP #-} +#if __GLASGOW_HASKELL__ >= 711+{-# OPTIONS_GHC -Wno-redundant-constraints #-}+#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Metrology.Poly -- Copyright   :  (C) 2013 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -33,7 +37,7 @@   -- * Term-level combinators    -- | The term-level arithmetic operators are defined by-  -- applying vertical bar(s) to the sides the dimensioned +  -- applying vertical bar(s) to the sides the dimensioned   -- quantities acts on.    -- ** Additive operations@@ -51,12 +55,12 @@    -- ** Comparison   qCompare, (|<|), (|>|), (|<=|), (|>=|), (|==|), (|/=|),-  qApprox, qNapprox,        +  qApprox, qNapprox,    -- * Nondimensional units, conversion between quantities and numeric values   numIn, (#), quOf, (%), showIn,   unity, redim, convert,-  defaultLCSU, constant, +  defaultLCSU, constant,    -- * Type-level unit combinators   (:*)(..), (:/)(..), (:^)(..), (:@)(..),@@ -66,13 +70,13 @@   type (%*), type (%/), type (%^),    -- * Creating quantity types-  Qu, MkQu_D, MkQu_DLN, MkQu_U, MkQu_ULN, +  Qu, MkQu_D, MkQu_DLN, MkQu_U, MkQu_ULN,    -- * Creating new dimensions   Dimension,    -- * Creating new units-  Unit(type BaseUnit, type DimOfUnit, conversionRatio), +  Unit(type BaseUnit, type DimOfUnit, conversionRatio),   Canonical,    -- * Numbers, the only built-in unit@@ -130,10 +134,10 @@ -- --   or -----   > inMeters x = x # Meter   +--   > inMeters x = x # Meter numIn :: forall unit dim lcsu n.          ( ValidDLU dim lcsu unit-         , Fractional n ) +         , Fractional n )       => Qu dim lcsu n -> unit -> n numIn (Qu val) u   = val * fromRational@@ -182,7 +186,7 @@ showIn x u = show (x # u) ++ " " ++ show u  -- | Dimension-keeping cast between different CSUs.-convert :: forall d l1 l2 n. +convert :: forall d l1 l2 n.   ( ConvertibleLCSUs d l1 l2   , Fractional n )   => Qu d l1 n -> Qu d l2 n@@ -217,7 +221,7 @@ infixl 6 |-| -- | Subtract two compatible quantities (|-|) :: (d1 @~ d2, Num n) => Qu d1 l n -> Qu d2 l n -> Qu d1 l n-a |-| b = a |+| qNegate b+(Qu a) |-| (Qu b) = Qu (a - b)  -- | Take the sum of a list of quantities qSum :: (Foldable f, Num n) => f (Qu d l n) -> Qu d l n@@ -239,4 +243,3 @@ -- | Divide a quantity by a scalar (|/) :: Fractional n => Qu a l n -> n -> Qu a l n (Qu a) |/ b = Qu (a / b)-
Data/Metrology/Qu.hs view
@@ -2,7 +2,7 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file defines the 'Qu' type that represents quantity    (a number paired with its measurement reference).@@ -12,8 +12,17 @@  {-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, UndecidableInstances,              ConstraintKinds, StandaloneDeriving, GeneralizedNewtypeDeriving,-             FlexibleInstances, RoleAnnotations, FlexibleContexts #-}+             FlexibleInstances, RoleAnnotations, FlexibleContexts,+             ScopedTypeVariables, CPP #-} +#if __GLASGOW_HASKELL__ >= 711+{-# OPTIONS_GHC -Wno-redundant-constraints #-}+#endif++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ module Data.Metrology.Qu where  import Data.Metrology.Dimensions@@ -22,8 +31,12 @@ import Data.Metrology.Z import Data.Metrology.LCSU +import Control.DeepSeq (NFData (..)) import Data.VectorSpace +import Text.Read+import Data.Coerce+ ------------------------------------------------------------- --- Internal ------------------------------------------------ -------------------------------------------------------------@@ -163,14 +176,14 @@       => Qu d0 l n  -- ^ /epsilon/       -> Qu d1 l n  -- ^ left hand side       -> Qu d2 l n  -- ^ right hand side-      -> Bool  +      -> Bool qApprox (Qu epsilon) (Qu a) (Qu b) = abs(a-b) <= epsilon --- | Compare two compatible quantities for approixmate inequality.  +-- | Compare two compatible quantities for approixmate inequality. -- @qNapprox e a b = not $ qApprox e a b@ qNapprox :: (d0 @~ d1, d0 @~ d2, Num n, Ord n)-       => Qu d0 l n  -- ^ /epsilon/      -       -> Qu d1 l n  -- ^ left hand side +       => Qu d0 l n  -- ^ /epsilon/+       -> Qu d1 l n  -- ^ left hand side        -> Qu d2 l n  -- ^ right hand side        -> Bool qNapprox (Qu epsilon) (Qu a) (Qu b) = abs(a-b) > epsilon@@ -208,6 +221,7 @@  deriving instance Eq n => Eq (Qu d l n) deriving instance Ord n => Ord (Qu d l n)+deriving instance NFData n => NFData (Qu d l n)  deriving instance AdditiveGroup n => AdditiveGroup (Qu d l n) instance VectorSpace n => VectorSpace (Qu d l n) where@@ -227,6 +241,22 @@ deriving instance (d ~ '[], Floating n)   => Floating (Qu d l n) deriving instance (d ~ '[], RealFrac n)   => RealFrac (Qu d l n) deriving instance (d ~ '[], RealFloat n)  => RealFloat (Qu d l n)++-- But don't do this for Read and Show, because other instances+-- are indeed sensible. Using the above technique here would make+-- other instances impossible. Also, note that GeneralizedNewtypeDeriving+-- puts the "Qu" constructor in Read and Show instances, so don't use+-- that.+instance Show n => Show (Qu '[] l n) where+  showsPrec = coerce (showsPrec :: Int -> n -> ShowS)+  show      = coerce (show      :: n -> String)+  showList  = coerce (showList  :: [n] -> ShowS)++instance Read n => Read (Qu '[] l n) where+  readsPrec    = coerce (readsPrec    :: Int -> ReadS n)+  readList     = coerce (readList     :: ReadS [n])+  readPrec     = coerce (readPrec     :: ReadPrec n)+  readListPrec = coerce (readListPrec :: ReadPrec [n])  ------------------------------------------------------------- --- Combinators ---------------------------------------------
Data/Metrology/Quantity.hs view
@@ -3,7 +3,7 @@ -- Module      :  Data.Metrology.Quantity -- Copyright   :  (C) 2014 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -11,7 +11,11 @@ -- quantities and types from other libraries. ------------------------------------------------------------------------------ -{-# LANGUAGE DataKinds, TypeFamilies, ConstraintKinds, UndecidableInstances #-}+{-# LANGUAGE DataKinds, TypeFamilies, ConstraintKinds, UndecidableInstances, CPP #-}++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif  module Data.Metrology.Quantity where 
Data/Metrology/Set.hs view
@@ -2,7 +2,7 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     Defines set-like operations on type-level lists. -}@@ -12,7 +12,7 @@ -- Module      :  Data.Metrology.Set -- Copyright   :  (C) 2013 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --
Data/Metrology/Show.hs view
@@ -1,5 +1,15 @@ {-# LANGUAGE PolyKinds, DataKinds, TypeOperators, FlexibleInstances,-             ScopedTypeVariables, FlexibleContexts, ConstraintKinds #-}+             ScopedTypeVariables, FlexibleContexts, ConstraintKinds, CPP,+             UndecidableInstances #-}++#if __GLASGOW_HASKELL__ < 709+{-# LANGUAGE OverlappingInstances #-}+#endif++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ {-# OPTIONS_GHC -fno-warn-orphans #-}  -----------------------------------------------------------------------------@@ -7,7 +17,7 @@ -- Module      :  Data.Metrology.Show -- Copyright   :  (C) 2013 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -71,8 +81,11 @@     build_string_helper [s] = s     build_string_helper (h:t) = h ++ " * " ++ build_string_helper t -instance (ShowUnitFactor (LookupList dims lcsu), Show n)-           => Show (Qu dims lcsu n) where+instance+#if __GLASGOW_HASKELL__ >= 709+    {-# OVERLAPPABLE #-}+#endif+    (ShowUnitFactor (LookupList dims lcsu), Show n)+    => Show (Qu dims lcsu n) where   show (Qu d) = show d ++                 (showFactor (Proxy :: Proxy (LookupList dims lcsu)))-
Data/Metrology/TH.hs view
@@ -3,7 +3,7 @@ -- Module      :  Data.Metrology.TH -- Copyright   :  (C) 2014 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -78,8 +78,13 @@ -- > instance Dimension Length declareDimension :: String -> Q [Dec] declareDimension str =-  return [ DataD [] name [] [NormalC name []] []-         , InstanceD [] (ConT ''Dimension `AppT` ConT name) [] ]+  return [ mkEmptyDataD name+#if __GLASGOW_HASKELL__ >= 711+         , InstanceD Nothing [] (ConT ''Dimension `AppT` ConT name) []+#else+         , InstanceD [] (ConT ''Dimension `AppT` ConT name) []+#endif+         ]   where     name = mkName str @@ -104,7 +109,7 @@   unit_instance <- [d| instance Unit $unit_type where                          type BaseUnit $unit_type = Canonical                          type DimOfUnit $unit_type = $dim |]-  return $ (DataD [] unit_name [] [NormalC unit_name []] [])+  return $ (mkEmptyDataD unit_name)            : unit_instance ++ show_instance   where     unit_name = mkName unit_name_str@@ -127,7 +132,7 @@   unit_instance <- [d| instance Unit $unit_type where                          type BaseUnit $unit_type = $base_unit                          conversionRatio _ = ratio |]-  return $ (DataD [] unit_name [] [NormalC unit_name []] [])+  return $ (mkEmptyDataD unit_name)            : unit_instance ++ show_instance   where     unit_name = mkName unit_name_str@@ -167,7 +172,7 @@                          type BaseUnit $unit_type = Canonical                          type DimOfUnit $unit_type = $unit_type |]   default_instance <- [d| type instance DefaultUnitOfDim $unit_type = $unit_type |]-  return $ (DataD [] unit_name [] [NormalC unit_name []] [])+  return $ (mkEmptyDataD unit_name)            : show_instance ++ dim_instance ++ unit_instance ++ default_instance   where     unit_name = mkName unit_name_str@@ -182,7 +187,8 @@ -- -- yields ----- > gravity_g :: ( Fractional n+-- > gravity_g :: forall lcsu n.+-- >              ( Fractional n -- >              , CompatibleUnit lcsu (Meter :/ Second :^ Two) ) -- >           => MkQu_ULN (Meter :/ Second :^ Two) lcsu n -- > gravity_g = 9.80665 % (undefined :: Meter :/ Second :^ Two)@@ -194,7 +200,12 @@   let lcsu = VarT lcsu_name       n    = VarT n_name       const_name = mkName name-      const_type = ForallT [PlainTV lcsu_name, PlainTV n_name]+      const_type =+#if __GLASGOW_HASKELL__ >= 900+                   ForallT [PlainTV lcsu_name SpecifiedSpec, PlainTV n_name SpecifiedSpec]+#else+                   ForallT [PlainTV lcsu_name, PlainTV n_name]+#endif                            [ mkClassP ''Fractional [n]                            , mkClassP ''CompatibleUnit [lcsu, unit_type] ] $                    ConT ''MkQu_ULN `AppT` unit_type `AppT` lcsu `AppT` n@@ -210,3 +221,16 @@ #else     mkClassP n tys = foldl AppT (ConT n) tys #endif++-- Make a DataD like `data <name> = <name>`.+mkEmptyDataD :: Name -> Dec+mkEmptyDataD name+#if __GLASGOW_HASKELL__ >= 801+  = DataD [] name [] Nothing [con] []+#elif __GLASGOW_HASKELL__ >= 711+  = DataD [] name [] Nothing [con] []+#else+  = DataD [] name [] [con] []+#endif+  where+    con = NormalC name []
Data/Metrology/Units.hs view
@@ -2,16 +2,24 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file defines the class Unit, which is needed for    user-defined units. -}  {-# LANGUAGE TypeFamilies, DataKinds, DefaultSignatures, MultiParamTypeClasses,-             ConstraintKinds, UndecidableInstances, FlexibleContexts,+             ConstraintKinds, UndecidableInstances, FlexibleContexts, CPP,              FlexibleInstances, ScopedTypeVariables, TypeOperators, PolyKinds #-} +#if __GLASGOW_HASKELL__ >= 711+{-# LANGUAGE UndecidableSuperClasses #-}+#endif++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ module Data.Metrology.Units where  import Data.Metrology.Z@@ -128,9 +136,13 @@ -- Conversion ratios for lists of units ----------------------------------------------------------------------- +type family Units (dfactors :: [Factor *]) :: Constraint where+  Units '[]                    = ()+  Units (F unit z ': dfactors) = (Unit unit, Units dfactors)+ -- | Classifies well-formed list of unit factors, and permits calculating a -- conversion ratio for the purposes of LCSU conversions.-class UnitFactor (units :: [Factor *]) where+class (Units units) => UnitFactor (units :: [Factor *]) where   canonicalConvRatioSpec :: Proxy units -> Rational  instance UnitFactor '[] where
Data/Metrology/Unsafe.hs view
@@ -5,12 +5,12 @@ -- Module      :  Data.Metrology.Unsafe -- Copyright   :  (C) 2013 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable -- -- This module exports the constructor of the 'Qu' type. This allows you--- to write code that takes creates and reads quantities at will, +-- to write code that takes creates and reads quantities at will, -- which may lead to dimension unsafety. Use at your peril. -- -- This module also exports 'UnsafeQu', which is a simple wrapper around
Data/Metrology/Validity.hs view
@@ -2,14 +2,18 @@     The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file defines validity checks on dimension, unit, and LCSU definitions. -}  {-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, PolyKinds,-             UndecidableInstances #-}+             UndecidableInstances, CPP #-} +#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ module Data.Metrology.Validity where  import Data.Metrology.LCSU@@ -33,7 +37,7 @@ type family MultUnitFactors (facts :: [Factor *]) where   MultUnitFactors '[] = Number   MultUnitFactors (F unit z ': units) = (unit :^ z) :* MultUnitFactors units-  + -- | Extract a unit from a dimension factor list and an LCSU type family UnitOfDimFactors (dims :: [Factor *]) (lcsu :: LCSU *) :: * where   UnitOfDimFactors dims lcsu = MultUnitFactors (LookupList dims lcsu)@@ -81,7 +85,7 @@ type family CanonicalUnitsOfFactors (fs :: [Factor *]) :: [*] where   CanonicalUnitsOfFactors '[] = '[]   CanonicalUnitsOfFactors (F u z ': fs) = (CanonicalUnit u) ': CanonicalUnitsOfFactors fs-    + -- | Check if an LCSU has consistent entries for the given unit. i.e. can the lcsu --   describe the unit? type family CompatibleUnit (lcsu :: LCSU *) (unit :: *) :: Constraint where
Data/Metrology/Vector.hs view
@@ -1,12 +1,16 @@-{-# LANGUAGE TypeOperators, FlexibleContexts, DataKinds, TypeFamilies,+{-# LANGUAGE TypeOperators, FlexibleContexts, DataKinds, TypeFamilies, CPP,              ScopedTypeVariables, ConstraintKinds, GeneralizedNewtypeDeriving #-} +#if __GLASGOW_HASKELL__ >= 711+{-# OPTIONS_GHC -Wno-redundant-constraints #-}+#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Metrology.Vector -- Copyright   :  (C) 2014 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable --@@ -18,7 +22,7 @@   -- * Term-level combinators    -- | The term-level arithmetic operators are defined by-  -- applying vertical bar(s) to the sides the dimensioned +  -- applying vertical bar(s) to the sides the dimensioned   -- quantities acts on.    -- ** Additive operations@@ -32,7 +36,7 @@    -- ** Multiplicative operations on vectors   (|*^|), (|^*|), (|^/|), (|.|),-  +   -- ** Exponentiation   (|^), (|^^), qNthRoot,   qSq, qCube, qSqrt, qCubeRoot,@@ -43,15 +47,15 @@   -- ** Affine operations   Point(..), QPoint, (|.-.|), (|.+^|), (|.-^|), qDistanceSq, qDistance,   pointNumIn, (.#), quOfPoint, (%.),-  +   -- ** Comparison   qCompare, (|<|), (|>|), (|<=|), (|>=|), (|==|), (|/=|),-  qApprox, qNapprox,        +  qApprox, qNapprox,    -- * Nondimensional units, conversion between quantities and numeric values   numIn, (#), quOf, (%), showIn,   unity, redim, convert,-  defaultLCSU, constant, +  defaultLCSU, constant,    -- * Type-level unit combinators   (:*)(..), (:/)(..), (:^)(..), (:@)(..),@@ -61,13 +65,13 @@   type (%*), type (%/), type (%^),    -- * Creating quantity types-  Qu, MkQu_D, MkQu_DLN, MkQu_U, MkQu_ULN, +  Qu, MkQu_D, MkQu_DLN, MkQu_U, MkQu_ULN,    -- * Creating new dimensions   Dimension,    -- * Creating new units-  Unit(type BaseUnit, type DimOfUnit, conversionRatio), +  Unit(type BaseUnit, type DimOfUnit, conversionRatio),   Canonical,    -- * Numbers, the only built-in unit@@ -297,7 +301,7 @@ -- --   or -----   > inMeters x = x # Meter   +--   > inMeters x = x # Meter numIn :: forall unit dim lcsu n.          ( ValidDLU dim lcsu unit          , VectorSpace n@@ -343,10 +347,10 @@ (%) = quOf  -- | Dimension-keeping cast between different CSUs.-convert :: forall d l1 l2 n. +convert :: forall d l1 l2 n.   ( ConvertibleLCSUs d l1 l2   , VectorSpace n-  , Fractional (Scalar n) ) +  , Fractional (Scalar n) )   => Qu d l1 n -> Qu d l2 n convert (Qu x) = Qu $ x ^* fromRational (   canonicalConvRatioSpec (Proxy :: Proxy (LookupList d l1))
Data/Metrology/Z.hs view
@@ -1,8 +1,8 @@ {- Data/Metrology/Z.hs- +    The units Package    Copyright (c) 2013 Richard Eisenberg-   eir@cis.upenn.edu+   rae@cs.brynmawr.edu     This file contains a definition of integers at the type-level, in terms    of a promoted datatype 'Z'.@@ -10,7 +10,14 @@  {-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, UndecidableInstances,              GADTs, PolyKinds, TemplateHaskell, ScopedTypeVariables,-             EmptyCase, CPP #-}+             EmptyCase, CPP, TypeSynonymInstances, FlexibleInstances,+             InstanceSigs, FlexibleContexts #-}+#if __GLASGOW_HASKELL__ >= 800+{-# LANGUAGE TypeApplications #-}+#endif+#if __GLASGOW_HASKELL__ >= 810+{-# LANGUAGE StandaloneKindSignatures #-}+#endif {-# OPTIONS_GHC -fno-warn-missing-signatures #-}  -----------------------------------------------------------------------------@@ -18,14 +25,14 @@ -- Module      :  Data.Metrology.Z -- Copyright   :  (C) 2013 Richard Eisenberg -- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)+-- Maintainer  :  Richard Eisenberg (rae@cs.brynmawr.edu) -- Stability   :  experimental -- Portability :  non-portable -- -- This module defines a datatype and operations to represent type-level -- integers. Though it's defined as part of the units package, it may be -- useful beyond dimensional analysis. If you have a compelling non-units--- use of this package, please let me (Richard, @eir@ at @cis.upenn.edu@)+-- use of this package, please let me (Richard, @rae@ at @cs.brynmawr.edu@) -- know. ----------------------------------------------------------------------------- @@ -36,7 +43,12 @@  module Data.Metrology.Z (   -- * The 'Z' datatype-  Z(..), Sing(..), SZ,+  Z(..),+#if MIN_VERSION_singletons(2,6,0)+  Sing, SZ(..),+#else+  Sing(..), SZ,+#endif  #if MIN_VERSION_singletons(1,0,0)   -- ** Defunctionalization symbols (these can be ignored)@@ -52,7 +64,7 @@   sSucc, sPred, sNegate,    -- ** Comparisons-  type (<), NonNegative,+  type (Data.Metrology.Z.<), NonNegative,    -- * Synonyms for certain numbers   One, Two, Three, Four, Five, MOne, MTwo, MThree, MFour, MFive,@@ -64,6 +76,9 @@   ) where  import Data.Singletons.TH+#if MIN_VERSION_singletons(3,0,0)+import Data.Singletons.Base.TH hiding ( Negate, sNegate, NegateSym0, NegateSym1 )+#endif import GHC.Exts ( Constraint )  -- | The datatype for type-level integers.@@ -137,15 +152,17 @@  -- | Less-than comparison type family (a :: Z) < (b :: Z) :: Bool where-  Zero  < Zero   = False-  Zero  < (S n)  = True-  Zero  < (P n)  = False-  (S n) < Zero   = False-  (S n) < (S n') = n < n'-  (S n) < (P n') = False-  (P n) < Zero   = True-  (P n) < (S n') = True-  (P n) < (P n') = n < n'+  -- fully qualify everywhere, because Data.Singletons.TH started exporting <+  -- at some point+  Zero  Data.Metrology.Z.< Zero   = False+  Zero  Data.Metrology.Z.< (S n)  = True+  Zero  Data.Metrology.Z.< (P n)  = False+  (S n) Data.Metrology.Z.< Zero   = False+  (S n) Data.Metrology.Z.< (S n') = n Data.Metrology.Z.< n'+  (S n) Data.Metrology.Z.< (P n') = False+  (P n) Data.Metrology.Z.< Zero   = True+  (P n) Data.Metrology.Z.< (S n') = True+  (P n) Data.Metrology.Z.< (P n') = n Data.Metrology.Z.< n'  -- | Check if a type-level integer is in fact a natural number type family NonNegative z :: Constraint where@@ -218,4 +235,3 @@  pSucc = sSucc pPred = sPred-
README.md view
@@ -36,8 +36,13 @@ conversion. Unit conversions are needed only when putting values in and out of quantities, or converting between two different CSUs. +Checking out units+------------------ +Units has a git submodule, so you'll want to use `git clone --recursive`. Example: +    git clone --recursive https://github.com/goldfirere/units+ User contributions ------------------ @@ -72,6 +77,12 @@     This also re-exports a similar set of definitions as `Data.Metrology.Poly`,     but provides numerical operations based on `vector-space` instead of the     standard numerical classes.++ -  __`Data.Metrology.Linear`__++    This exports a set of definitions for interoperability with the `linear`+    package. This is /not/ a top-level import; generally, import this with+    `Data.Metrology.Poly` as well.   -  __`Data.Metrology.Internal`__ 
− Tests/Compile/CGS.hs
@@ -1,15 +0,0 @@-{-# LANGUAGE DataKinds, TypeOperators #-}--module Tests.Compile.CGS where--import Data.Metrology-import Data.Metrology.SI-import qualified Data.Dimensions.SI as D--type CGS = MkLCSU '[ (D.Length, Centi :@ Meter)-                   , (D.Mass, Gram)-                   , (D.Time, Second) ]--type CGSLength = MkQu_DLN D.Length CGS Double-type CGSMass = MkQu_DLN D.Mass CGS Double-type CGSTime = MkQu_DLN D.Time CGS Double
− Tests/Compile/EvalType.hs
@@ -1,22 +0,0 @@-{- Tests evalType-   Copyright (c) 2014 Richard Eisenberg--}--{-# LANGUAGE TemplateHaskell, FlexibleInstances, DataKinds, CPP,-             KindSignatures #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}--module Tests.Compile.EvalType where--import Data.Metrology.TH-import Data.Metrology.SI-import Data.Metrology--instance Show $(evalType [t| Length |]) where-  show x = x `showIn` Meter--#if MIN_VERSION_th_desugar(1,5,0) && __GLASGOW_HASKELL__ < 709-  -- See #34-instance Show $(evalType [t| Volume |]) where-  show x = x `showIn` Liter-#endif
− Tests/Compile/Lcsu.hs
@@ -1,37 +0,0 @@-{-# LANGUAGE TypeFamilies, DataKinds #-}--module Tests.Compile.Lcsu where--import Data.Metrology.Poly hiding (LCSU)--data Length = Length-data Time = Time--data Meter = Meter-data Second = Second--data Centi = Centi--instance Dimension Length-instance Dimension Time--instance Unit Meter where-  type BaseUnit Meter = Canonical-  type DimOfUnit Meter = Length-instance Unit Second where-  type BaseUnit Second = Canonical-  type DimOfUnit Second = Time--instance Unit Centi where-  type BaseUnit Centi = Meter-  conversionRatio _ = 0.01--data Foot = Foot-instance Unit Foot where-  type BaseUnit Foot = Meter-  conversionRatio _ = 0.3048--type LCSU = MkLCSU '[(Length, Meter),  (Time, Second)]--inMeters :: Qu '[F Length One] LCSU Double-inMeters = quOf 3 Meter
− Tests/Compile/MetrologySynonyms.hs
@@ -1,153 +0,0 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE EmptyDataDecls #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeOperators #-}--module Tests.Compile.MetrologySynonyms where--import           Data.Metrology-import           Data.Metrology.SI.Poly-import           Data.Metrology.Unsafe-import           Text.Printf--------------------------------------------------------------------- Pretty Printing Functions-------------------------------------------------------------------ppValF :: PrintfArg x => String -> Qu d l x -> String-ppValF fmtStr (Qu x) = printf fmtStr x --  ++ showFactor (Proxy :: Proxy (LookupList dims lcsu)))--ppValE :: PrintfArg x => Int -> Qu d l x -> String-ppValE d (Qu x) = ret-  where-    fmtStr :: String-    fmtStr = printf "%%.%de" d-    -    protoStr :: String-    protoStr = printf fmtStr x--    (valPart,expPart) = break (=='e') protoStr-    -    ret = case expPart of-      "e0" -> valPart-      _ -> printf "%s \\times 10^{%s}" valPart (drop 1 expPart)----------------------------------------------------------------------- Nonweighted units-------------------------------------------------------------------type PerSecond =  Number :/ Second-type PerCm3 =  Second :^ MThree-type PerCm2 =  Second :^ MTwo-type PerCm = (Centi :@ Meter) :^ MTwo -type GHz =  (Giga :@ Hertz)--------------------------------------------------------------------- Weighted units--------------------------------------------------------------------- densities-type GramPerCm2 = Gram :* PerCm2-type GramPerCm3 = Gram :* PerCm3 --type JouleM3 = Joule :/ (Meter :^ Three)----- see the table in http://en.wikipedia.org/wiki/Spectral_irradiance-type SpectralRadiance = Watt :/ (Meter :^ Two) :/ Hertz----- | Spectral Flux Density--- type SpectralFluxDensity = '[ '(Mass, POne), '(Time, NTwo)] --- |Unit of EDP-data Jansky = Jansky-instance Show Jansky where show _ = "Jy"--instance Unit Jansky where-  type BaseUnit Jansky = Joule :/ (Meter :^ Two) :* Second-  conversionRatio _ = 1e-26----- energies-data ElectronVolt = ElectronVolt-instance Show ElectronVolt where show _ = "eV"-instance Unit ElectronVolt where-  type BaseUnit ElectronVolt = Joule -  conversionRatio _ = 1.60217657e-19---type JouleSecond = Joule :* Second----- velocities-type KmPerSec = (Kilo :@ Meter) :/ Second-type MPerSec = Meter :/ Second-type CmPerSec = (Centi :@ Meter) :/ Second--type Kg = Kilo :@ Gram--type GramPerMole = Gram :/ Mole---data AU = AU-instance Show AU where show _ = "au"-instance Unit AU where-  type BaseUnit AU = Meter-  conversionRatio _ = 149597870700 --data Parsec = Parsec-instance Show Parsec where show _ = "pc"-instance Unit Parsec where-  type BaseUnit Parsec = Meter-  conversionRatio _ = 3.08567758e16------ squared velocities-type Cm2PerSec2 = CmPerSec :^ Two-type Meter2PerSec2 = MPerSec :^ Two-type Sec2PerMeter2 = MPerSec :^ MTwo---- areas-type Meter2 = Meter :^ Two-type Cm2 = (Centi :@ Meter) :^ Two--type SIGCUnit =-  (Meter :^ Three) :* ((Kilo :@ Gram) :^ MOne) :* (Second :^ MTwo)-type SIkBUnit = Joule :/ Kelvin---------------------------------------------------------------------- Electric Units------------------------------------------------------------------type VoltPerCm = Volt :/ (Centi :@ Meter)-type KVPerCm = (Kilo :@ Volt) :/ (Centi :@ Meter)---type CoulombPerCm2 = Coulomb :/ Cm2---- eps0-type SIPermittivityUnit = -  ((Kilo :@ Gram) :^ MOne) :*-  (Meter :^ MThree) :*-  (Second :^ Four) :*-  (Ampere :^ Two)---- mu0-type SIPermeabilityUnit = -  ((Kilo :@ Gram) :^ One) :*-  (Meter :^ One) :*-  (Second :^ MTwo) :*-  (Ampere :^ MTwo)----- dipole moment-data Debye = Debye-instance Unit Debye where-  type BaseUnit Debye = Coulomb :* Meter-  conversionRatio _ = 1e-21/299792458-  -  
− Tests/Compile/NoVector.hs
@@ -1,10 +0,0 @@-{-# OPTIONS_GHC -fno-warn-type-defaults -fno-warn-missing-signatures #-}--module Tests.Compile.NoVector where--import Data.Metrology-import Data.Metrology.SI--x = 5 % Meter-y = 2 % Second-vel = x |/| y
− Tests/Compile/Physics.hs
@@ -1,76 +0,0 @@-{-# LANGUAGE TypeOperators, ConstraintKinds, ScopedTypeVariables, TypeFamilies,-             FlexibleContexts, DataKinds #-}--module Tests.Compile.Physics where--import Data.Dimensions.SI-import Data.Metrology.Poly-import Data.Metrology.SI.Poly ( SI )-import Data.Units.SI-import Data.Units.SI.Prefixes-import Tests.Compile.CGS--type Position = Length--cur_pos :: MkQu_DLN Position lcsu Double-        -> MkQu_DLN Velocity lcsu Double-        -> MkQu_DLN Acceleration lcsu Double-        -> MkQu_DLN Time lcsu Double-        -> MkQu_DLN Position lcsu Double-cur_pos x0 v a t = x0 |+| (v |*| t) |+| (0.5 *| a |*| (t |^ sTwo))--siPos :: MkQu_DLN Position SI Double-siPos = 3 % Meter--siVel :: MkQu_DLN Velocity SI Double-siVel = 2 % (Meter :/ Second)--siAcc :: MkQu_DLN Acceleration SI Double-siAcc = 10 % (Meter :/ Second :/ Second)--siTime :: MkQu_DLN Time SI Double-siTime = 4 % Second--siMass :: MkQu_DLN Mass SI Double-siMass = 1 % (Kilo :@ Gram)--cgsPos :: MkQu_DLN Position CGS Double-cgsPos = 3 % Meter--cgsVel :: MkQu_DLN Velocity CGS Double-cgsVel = 2 % (Meter :/ Second)--cgsAcc :: MkQu_DLN Acceleration CGS Double-cgsAcc = 10 % (Meter :/ Second :/ Second)--cgsTime :: MkQu_DLN Time CGS Double-cgsTime = 4 % Second--cgsMass :: MkQu_DLN Mass CGS Double-cgsMass = 1 % (Kilo :@ Gram)--kinetic_energy :: MkQu_DLN Mass lcsu Double-               -> MkQu_DLN Velocity lcsu Double-               -> MkQu_DLN Energy lcsu Double-kinetic_energy m v = redim $ 0.5 *| m |*| v |*| v--momentum :: MkQu_DLN Mass l Double-         -> MkQu_DLN Velocity l Double-         -> MkQu_DLN Momentum l Double-momentum m v = redim $ m |*| v--g_earth :: CompatibleUnit lcsu (Meter :/ (Second :^ Two))-        => MkQu_DLN Acceleration lcsu Double-g_earth = 9.8 % (Meter :/ (Second :^ sTwo))--distance :: MkQu_DLN Velocity lcsu Double-         -> MkQu_DLN Acceleration lcsu Double-         -> MkQu_DLN Time lcsu Double-         -> MkQu_DLN Length lcsu Double-distance v a t = redim $ v |*| t |+| (0.5 *| a |*| t |*| t)--sum :: Num n => [Qu dims l n] -> Qu dims l n-sum = foldr (|+|) zero--squareAll :: Fractional n => [Qu dims l n] -> [Qu (dims @* Two) l n]-squareAll = map (|^ sTwo)
− Tests/Compile/Quantity.hs
@@ -1,35 +0,0 @@-{- Test Quantity instance-   Copyright (c) 2014 Richard Eisenberg--}--{-# LANGUAGE DataKinds, TypeFamilies, UndecidableInstances #-}--module Tests.Compile.Quantity where--import Data.Metrology.Poly-import Data.Metrology.Quantity-import Data.Metrology.SI.Poly-import Data.Metrology.SI   ()  -- DefaultLCSU instances--len1 :: Length SI Double-len1 = 5 % Meter--len2 :: Length SI Double-len2 = fromQuantity len1--len3 :: Length SI Double-len3 = toQuantity len1--force1, force2, force3 :: Energy DefaultLCSU Double-force1 = 10 % Joule-force2 = fromQuantity force1-force3 = toQuantity force1--newtype MyTime = MyTime { getTime :: Double }   -- measured in seconds--instance Quantity MyTime where-  type QuantityUnit MyTime = Second-  type QuantityLCSU MyTime = SI--  fromQuantity = MyTime . (# Second)-  toQuantity = (% Second) . getTime
− Tests/Compile/Readme.hs
@@ -1,98 +0,0 @@-{-# LANGUAGE TypeFamilies, TypeOperators, DataKinds #-}--module Tests.Compile.Readme where--    import Data.Metrology.Poly hiding (LCSU)--    data LengthDim = LengthDim  -- each dimension is a datatype that acts as its own proxy-    instance Dimension LengthDim--    data TimeDim = TimeDim-    instance Dimension TimeDim--    type VelocityDim = LengthDim :/ TimeDim-    data Meter = Meter-    instance Unit Meter where           -- declare Meter as a Unit-      type BaseUnit Meter = Canonical   -- Meters are "canonical"-      type DimOfUnit Meter = LengthDim  -- Meters measure Lengths-    instance Show Meter where           -- Show instances are optional but useful-      show _ = "m"                      -- do *not* examine the argument!--    data Foot = Foot-    instance Unit Foot where-      type BaseUnit Foot = Meter        -- Foot is defined in terms of Meter-      conversionRatio _ = 0.3048        -- do *not* examine the argument!-                                        -- We don't need to specify the `DimOfUnit`;-                                        -- it's implied by the `BaseUnit`.-    instance Show Foot where-      show _ = "ft"--    data Second = Second-    instance Unit Second where-      type BaseUnit Second = Canonical-      type DimOfUnit Second = TimeDim-    instance Show Second where-      show _ = "s"--    type LCSU = MkLCSU '[(LengthDim, Meter), (TimeDim, Second)]--    type Length = MkQu_DLN LengthDim LCSU Double-      -- Length stores lengths in our defined LCSU, using `Double` as the numerical type-    type Length' = MkQu_ULN Foot LCSU Double-      -- same as Length. Note the `U` in `MkQu_ULN`, allowing it to take a unit--    type Time = MkQu_DLN TimeDim LCSU Double--    extend :: Length -> Length            -- a function over lengths-    extend x = redim $ x |+| (1 % Meter)--    inMeters :: Length -> Double          -- extract the # of meters-    inMeters = (# Meter)                  -- more on this later--    conversion :: Length                  -- mixing units-    conversion = (4 % Meter) |+| (10 % Foot)--    vel :: Length %/ Time                 -- The `%*` and `%/` operators allow-                                          -- you to combine types-    vel = (3 % Meter) |/| (2 % Second)--    data Kilo = Kilo-    instance UnitPrefix Kilo where-      multiplier _ = 1000--    kilo :: unit -> Kilo :@ unit-    kilo = (Kilo :@)--    longWayAway :: Length-    longWayAway = 150 % kilo Meter--    longWayAwayInMeters :: Double-    longWayAwayInMeters = longWayAway # Meter  -- 150000.0--    type MetersPerSecond = Meter :/ Second-    type Velocity1 = MkQu_ULN MetersPerSecond LCSU Double--    speed :: Velocity1-    speed = 20 % (Meter :/ Second)--    type Velocity2 = Length %/ Time    -- same type as Velocity1--    type MetersSquared = Meter :^ Two-    type Area1 = MkQu_ULN MetersSquared LCSU Double-    type Area2 = Length %^ Two        -- same type as Area1--    roomSize :: Area1-    roomSize = 100 % (Meter :^ sTwo)--    roomSize' :: Area1-    roomSize' = 100 % (Meter :* Meter)--    type Velocity3 = (MkQu_ULN Number LCSU Double) %/ Time %* Length-    addVels :: Velocity1 -> Velocity1 -> Velocity3-    addVels v1 v2 = redim $ (v1 |+| v2)--    type instance DefaultUnitOfDim LengthDim = Meter-    type instance DefaultUnitOfDim TimeDim   = Second--    -- type Length = MkQu_D LengthDim-
− Tests/Compile/Simulator.hs
@@ -1,126 +0,0 @@-{- Copyright (c) 2013-4 Richard Eisenberg--This file demonstrates some of `units`'s capabilities by building up a simple-physics simulator.--}--{-# LANGUAGE TypeOperators, TypeFamilies, QuasiQuotes #-}--module Tests.Compile.Simulator where--import Data.Metrology.SI-import Data.Metrology.Show ()-import Data.Metrology.Vector---- We never want to add positions! QPoint protects us from this.-type Position = QPoint Length---- +x = right--- +y = up---- We still want the "outer" type to be Qu, not the pair. So push the pairing--- operation down to the Qu's representation.-type family Vec2D x where-  Vec2D (Qu d l n) = Qu d l (n, n)---- An object in our little simulation-data Object = Object { mass :: Mass-                     , rad  :: Length-                     , pos  :: Vec2D Position-                     , vel  :: Vec2D Velocity }-  deriving Show--type Universe = [Object]---- updating takes two passes: move everything according to their own positions--- and gravity (ignoring pulls between objects), and then look for collisions--- and update collided objects' positions and velocities accordingly. This might--- fail if three objects were to collide in a row all at once.--g :: Vec2D Acceleration-g = (0,-9.8)% [si| m/s^2 |]  -- could also be Meter :/ (Second :^ sTwo)--g_universe :: Force %* Length %^ Two %/ (Mass %^ Two)-g_universe = 6.67e-11 % [si| N m^2 / kg^2 |]--update :: Time -> Universe -> Universe-update dt objs-  = let objs1 = map (updateNoColls dt objs) objs in-    updateColls objs1---- update without taking collisions into account-updateNoColls :: Time -> Universe -> Object -> Object-updateNoColls dt univ obj@(Object { mass = m, pos = x, vel = dx })-  = let new_pos = x |.+^| dx |^*| dt  -- new position-        v1 = dx |+| g |^*| dt         -- new velocity w.r.t. downward gravity-        f = gravityAt univ x m-        a = f |^/| m-        v2 = v1 |+| a |^*| dt         -- new velocity also with mutual gravity-    in obj { pos = new_pos, vel = v2 }---- calculate the gravity at a point from all other masses-gravityAt :: Universe -> Vec2D Position -> Mass -> Vec2D Force-gravityAt univ p m = qSum (map gravity_at_1 univ)-  where-    -- gravity caused by just one point-    gravity_at_1 (Object { mass = m1, pos = pos1 })-      = let r = p |.-.| pos1-            f = g_universe |*| m1 |*| m |*^| r |^/| (qMagnitude r |^ sThree)-        in-        if qMagnitude r |>| (zero :: Length)  -- exclude the point itself!-        then redim f -        else zero---- update by collisions-updateColls :: Universe -> Universe-updateColls objs-  = let collisions = findCollisions objs in-    map resolveCollision collisions---- returns a list of collisions, as pairs of an object with, perhaps,--- a collision partner-findCollisions :: Universe -> [(Object, Maybe Object)]-findCollisions objs-  = map (findCollision objs) objs---- check for collisions for one particular Object-findCollision :: Universe -> Object -> (Object, Maybe Object)-findCollision [] obj = (obj, Nothing)-findCollision (other : rest) obj-  | colliding other obj-  = (obj, Just other)-  | otherwise-  = findCollision rest obj---- are two objects in contact?-colliding :: Object -> Object -> Bool-colliding (Object { pos = x1, rad = rad1 })-          (Object { pos = x2, rad = rad2 })-  = let distance = qDistance x1 x2 in-    distance |>| (zero :: Length) && distance |<=| (rad1 |+| rad2)---- resolve the collision between two objects, updating only the first--- object in the pair. The second object will be updated in a separate--- (symmetric) call.-resolveCollision :: (Object, Maybe Object) -> Object-resolveCollision (obj, Nothing) = obj-resolveCollision (obj@Object { mass = m1, rad = rad1-                             , pos = z1, vel = v1 },-                Just (Object { mass = m2, rad = rad2-                             , pos = z2, vel = v2 }))-  = let -- c :: Vec2D Length-        c = z2 |.-.| z1   -- vector from z1 to z2--        -- vc1, vc2, vd1, vc1', v1' :: Vec2D Velocity-        vc1 = c `qProject` v1  -- component of v1 along c-        vc2 = c `qProject` v2  -- component of v2 along c-        vd1 = v1 |-| vc1       -- component of v1 orthogonal to c-        vc1' = (m1 |*^| vc1 |-| m2 |*^| vc2 |+| 2 *| m2 |*^| vc2) |^/| (m1 |+| m2)-                               -- new component of v1 along c-        v1' = vc1' |+| vd1     -- new v1--          -- also, move object 1 to be out of contact with object 2-        z1' = z2 |.-^| (rad1 |+| rad2) |*^| qNormalized c-    in-    obj { pos = z1', vel = v1' }-
− Tests/Compile/T23.hs
@@ -1,12 +0,0 @@-{- Regression test for #23 -}--{-# LANGUAGE TypeOperators, ConstraintKinds, FlexibleContexts #-}--module Tests.Compile.T23 where--import Data.Metrology.Poly-import Data.VectorSpace--ratio :: (d1 @~ d2, VectorSpace n, Fractional (Scalar n), Fractional n)-      => Qu d1 l n -> Qu d2 l n -> n-ratio x y = (x |/| y) # Number
− Tests/Compile/TH.hs
@@ -1,25 +0,0 @@-{-# LANGUAGE TemplateHaskell, DataKinds, TypeFamilies #-}--module Tests.Compile.TH where--import Data.Metrology.TH-import Data.Metrology.Poly-import qualified Data.Metrology as Mono--$(declareDimension "Length")-$(declareCanonicalUnit "Meter" [t| Length |] (Just "m"))-$(declareDerivedUnit "Foot" [t| Meter |] 0.3048 Nothing)--type MyLCSU = MkLCSU '[(Length, Meter)]--len1 :: MkQu_DLN Length MyLCSU Double-len1 = 5 % Meter--len2 :: MkQu_DLN Length MyLCSU Double-len2 = 10 % Foot--$(declareMonoUnit "Second" (Just "s"))-type Time = MkQu_D Second--time :: Time-time = 10 Mono.% Second
− Tests/Compile/UnitParser.hs
@@ -1,46 +0,0 @@-{- Test units package quasiquoter mechanism-   Copyright (c) 2014 Richard Eisenberg--}--{-# LANGUAGE QuasiQuotes, CPP, DataKinds #-}--module Tests.Compile.UnitParser where--import Tests.Compile.UnitParser.Quoters ( ms )-import Data.Metrology.SI-import Data.Metrology--len1, len2 :: Length-len1 = 5 % [ms| m |]-len2 = redim $ 10 % [ms| s km / ms |]--vel1, vel2, vel3, vel4 :: Velocity-vel1 = 5 % [ms| m/s |]-vel2 = redim $ 10 % [ms| m s/s^2 |]-vel3 = redim $ 15 % [ms| m 1 / s 1 |]-vel4 = redim $ 20 % [ms| m /(1*1*s) |]--acc1, acc2 :: Acceleration-acc1 = 5 % [ms| m/s^2 |]-acc2 = redim $ 10 % [ms| m/s s |]--#if __GLASGOW_HASKELL >= 709-len3 :: Length-len3 = 15 % [unit| μm |]--freq :: Frequency-freq = 100 % [unit| MHz |]-#endif--lenty :: MkQu_U [ms| m |]-lenty = 5 % Meter--velty :: MkQu_U [ms| m/s |]-velty = 5 % (Meter :/ Second)--freqty :: MkQu_U [ms| s^-1 |]-freqty = 5 % Hertz--num1, num2 :: Count-num1 = 3 % [ms|  |]-num2 = 4 % [ms| 1 |]
− Tests/Compile/UnitParser/Quoters.hs
@@ -1,18 +0,0 @@-{- Define test quasiquoters-   Copyright (c) 2014 Richard Eisenberg--}--{-# LANGUAGE TemplateHaskell, CPP #-}--module Tests.Compile.UnitParser.Quoters where--import Data.Metrology.Parser-import Data.Metrology.SI--$(makeQuasiQuoter "ms" [''Milli, ''Kilo] [''Meter, ''Second])--#if __GLASGOW_HASKELL__ >= 709-$(do units <- allUnits-     prefixes <- allPrefixes-     makeQuasiQuoter "unit" units prefixes)-#endif
− Tests/Compile/Units.hs
@@ -1,40 +0,0 @@-{-# LANGUAGE DataKinds, TypeFamilies, TypeOperators #-}--module Tests.Compile.Units where--import Data.Metrology--data Meter = Meters-data Foot = Feet-data Yard = Yards--type Length = MkQu_U Meter-type Time = MkQu_U Second--data LengthD = LengthD-instance Dimension LengthD-data TimeD = TimeD-instance Dimension TimeD--instance Unit Meter where-  type BaseUnit Meter = Canonical-  type DimOfUnit Meter = LengthD--instance Unit Foot where-  type BaseUnit Foot = Meter-  conversionRatio _ = 0.3048--instance Unit Yard where-  type BaseUnit Yard = Foot-  conversionRatio _ = 3--data Second = Seconds-instance Unit Second where-  type BaseUnit Second = Canonical-  type DimOfUnit Second = TimeD--data Hertz = Hertz-instance Unit Hertz where-  type BaseUnit Hertz = Number :/ Second-  conversionRatio _ = 1-
− Tests/Imperial.hs
@@ -1,27 +0,0 @@-{-# LANGUAGE TypeOperators, TypeFamilies, ImplicitParams, NoMonomorphismRestriction #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--module Tests.Imperial where--import Data.Metrology-import Data.Metrology.SI--import Test.Tasty-import Test.Tasty.HUnit-import Test.HUnit.Approx--data Mile = Mile-instance Unit Mile where-  type BaseUnit Mile = Meter-  conversionRatio _ = 1609.34--data Pound = Pound-instance Unit Pound where-  type BaseUnit Pound = Kilo :@ Gram-  conversionRatio _ = 0.453592--tests =-  testGroup "Imperial" -  [ testCase "Mile" ((1 % Mile :: Length) # Meter @?~ 1609.34) -  , testCase "Pound"  ((1 % Pound :: Mass) # kilo Gram @?~ 0.453592) ] -  
− Tests/LennardJones.hs
@@ -1,213 +0,0 @@-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE ImplicitParams #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--module Tests.LennardJones where--import Data.Metrology.Poly-import Data.Metrology.Z-import Data.Metrology.SI.Mono         ()-import Data.Metrology.SI.PolyTypes-import Data.Metrology.SI.Poly (SI)-import Data.Units.SI-import Data.Units.SI.Prefixes-import qualified Data.Dimensions.SI as D--- import Data.Metrology.Show--import Test.Tasty-import Test.Tasty.HUnit-import Test.HUnit.Approx--type Six      = S Five-type Seven    = S Six-type Eight    = S Seven-type Nine     = S Eight-type Ten      = S Nine-type Eleven   = S Ten-type Twelve   = S Eleven-type Thirteen = S Twelve---sSix     = SS sFive-sSeven   = SS sSix     -sEight   = SS sSeven   -sNine    = SS sEight   -sTen     = SS sNine    -sEleven  = SS sTen     -sTwelve  = SS sEleven  -sThirteen= SS sTwelve  ---data EV = EV-instance Show EV where show _ = "eV"-instance Unit EV where-  type BaseUnit EV = Joule -  conversionRatio _ = 1.60217657e-19--data ProtonMass = ProtonMass-instance Show ProtonMass where show _ = "m_p"-instance Unit ProtonMass where-  type BaseUnit ProtonMass = Kilo :@ Gram-  conversionRatio _ = 1.67262178e-27--data Å = Å-instance Show Å where show _ = "Å"-instance Unit Å where-  type BaseUnit Å = Meter-  conversionRatio _ = 1e-8----- | chemist's unit-type CU = MkLCSU '[ (D.Length, Å)-                  , (D.Mass, ProtonMass)-                  , (D.Time, Pico :@ Second)]--protonMass :: Mass SI Float-protonMass =  1 % ProtonMass--sigmaAr :: Length SI Float-sigmaAr = 3.4e-8 % Meter--epsAr :: Energy SI Float-epsAr = 1.68e-21 % Joule--ljForce :: Length SI Float -> Force SI Float-ljForce r = redim $ 24 *| epsAr |*| sigmaAr|^ sSix |/| r |^ sSeven-                |-| 48 *| epsAr |*| sigmaAr|^ sTwelve |/| r |^ sThirteen---type AParameterDim = D.Energy :* D.Length :^ Twelve-type BParameterDim = D.Energy :* D.Length :^ Six--type APara = MkQu_DLN AParameterDim-type BPara = MkQu_DLN BParameterDim--ljForceP :: Energy l Float -> Length l Float -> Length l Float -> Force l Float-ljForceP eps sigma r -  = redim $ 24 *| eps |*| sigma|^ sSix |/| r |^ sSeven-        |-| 48 *| eps |*| sigma|^ sTwelve |/| r |^ sThirteen---aParaAr :: (ConvertibleLCSUs_D D.Length SI l , ConvertibleLCSUs_D D.Energy SI l )=> APara l Float-aParaAr = 48 *|  convert epsAr  |*| convert sigmaAr|^ sTwelve--bParaAr :: (ConvertibleLCSUs_D D.Length SI l , ConvertibleLCSUs_D D.Energy SI l )=>  BPara l Float-bParaAr = 24 *|  convert epsAr  |*| convert sigmaAr|^ sSix------ljForcePOpt :: APara l Float -> BPara l Float -> Length l Float -> Force l Float-ljForcePOpt a b r -  = redim $ b |/| r |^ sSeven-        |-| a |/| r |^ sThirteen---sigmaAr' :: (DefaultConvertibleLCSU_D D.Length l) => Length l Float-sigmaAr' = constant $ 3.4e-8 % Meter-epsAr' :: (DefaultConvertibleLCSU_D D.Energy l) => Energy l Float-epsAr' = constant $ 1.68e-21 % Joule---aParaAr' :: (DefaultConvertibleLCSU_D AParameterDim l) => APara l Float-aParaAr' = constant $ 48 *|  epsAr'  |*| sigmaAr'|^ sTwelve--bParaAr' :: (DefaultConvertibleLCSU_D BParameterDim l) => BPara l Float-bParaAr' = constant $ 24 *|  epsAr'  |*| sigmaAr'|^ sSix----sigmaAr'' :: (ConvertibleLCSUs_D D.Length CU l) => Length l Float-sigmaAr'' = convert $ (3.4e-8 % Meter :: Length CU Float)-epsAr'' :: (ConvertibleLCSUs_D D.Energy CU l) => Energy l Float-epsAr'' = convert $ (1.68e-21 % Joule :: Energy CU Float)--aParaAr'' :: (ConvertibleLCSUs_D AParameterDim CU l) => APara l Float-aParaAr'' = convert $ ((48 :: Float) *|  epsAr'  |*| sigmaAr'|^ sTwelve :: APara CU Float)--bParaAr'' :: (ConvertibleLCSUs_D BParameterDim CU l) => BPara l Float-bParaAr'' = convert $ ((24 :: Float) *|  epsAr'  |*| sigmaAr'|^ sSix :: BPara CU Float)--tests :: TestTree-tests =-  let ?epsilon = 0.0001 in -- need this because we need Floats, not Doubles!-  let ans :: (ConvertibleLCSUs_D D.Length SI l, ConvertibleLCSUs_D D.Energy SI l) => Force l Float-      ans = ljForceP (convert epsAr) (convert sigmaAr) (4 % Å)-      val = 9.3407324e-14-  in-  testGroup "LennardJones"-  [ testCase "NaN" (assert (isNaN $ ljForce (4 % Å) # Newton))-  , testCase "NaNPoly" (assert (isNaN $ (ljForceP (convert epsAr) (convert sigmaAr) (4 % Å) :: Force SI Float) # Newton))-  , testCase "CU" ((ljForceP (convert epsAr) (convert sigmaAr) (4 % Å) :: Force CU Float) # Newton @?~ val)-  , testCase "ansNaN" (assert $ isNaN $ (ans :: Force SI Float) # Newton)-  , testCase "ansCU" ((ans :: Force CU Float) # Newton @?~ val)-  , testCase "optNaN" (assert $ isNaN $ (ljForcePOpt aParaAr bParaAr (4%Å) :: Force SI Float) # Newton)-  , testCase "optCU" ((ljForcePOpt aParaAr bParaAr (4%Å) :: Force CU Float) # Newton @?~ val)-  , testCase "precompNaN" (assert $ isNaN $ (ljForcePOpt aParaAr' bParaAr' (4%Å) :: Force SI Float) # Newton)-  , testCase "precompNaN2" (assert $ isNaN $ (ljForcePOpt aParaAr' bParaAr' (4%Å) :: Force CU Float) # Newton)-  , testCase "precompPolyNaN" (assert $ isNaN $ (ljForcePOpt aParaAr'' bParaAr'' (4%Å) :: Force SI Float) # Newton)-  , testCase "precompPolyCU" ((ljForcePOpt aParaAr'' bParaAr'' (4%Å) :: Force CU Float) # Newton @?~ val) ]-{--main :: IO ()-main = do--  putStrLn "He insists that it's better to do chemistry in CU than SI."-  putStrLn "For example, the attractive force between two Argon atom at the distance of 4Å is:"-  putStrLn $ ljForce (4 % Å) `showIn` (Newton)-  putStrLn "Oops, let's do it polymorphically:"-  putStrLn $ (ljForceP (convert epsAr) (convert sigmaAr) (4 % Å) :: Force SI Float) `showIn` (Newton)-  putStrLn "I can't do it in SI! On the other hand in CU we can:"-  putStrLn $ (ljForceP (convert epsAr) (convert sigmaAr) (4 % Å) :: Force CU Float) `showIn` (Newton)---  -- how would you type it polymorphically (not using the default LCSU)?-  let ans :: (ConvertibleLCSUs_D D.Length SI l, ConvertibleLCSUs_D D.Energy SI l)=> Force l Float-      ans = ljForceP (convert epsAr) (convert sigmaAr) (4 % Å)--  putStrLn "We compare again:"  -  putStrLn $ (ans :: Force SI Float) `showIn` (Newton)-  putStrLn $ (ans :: Force CU Float) `showIn` (Newton)---  putStrLn $ "Let's optimize the computation by precomputing all the constants."-  putStrLn $ (ljForcePOpt aParaAr bParaAr (4%Å):: Force SI Float) `showIn` Newton-  putStrLn $ (ljForcePOpt aParaAr bParaAr (4%Å):: Force CU Float) `showIn` Newton--  putStrLn $ "We cannot use the default LCSU for calculating constants in this case."-  putStrLn $ (ljForcePOpt aParaAr' bParaAr' (4%Å):: Force SI Float) `showIn` Newton-  putStrLn $ (ljForcePOpt aParaAr' bParaAr' (4%Å):: Force CU Float) `showIn` Newton-  -  putStrLn $ "We must pay attention in which LCSU the constants are computed in."-  putStrLn $ (ljForcePOpt aParaAr'' bParaAr'' (4%Å):: Force SI Float) `showIn` Newton-  putStrLn $ (ljForcePOpt aParaAr'' bParaAr'' (4%Å):: Force CU Float) `showIn` Newton  ----{--- output ----A chemist said his favorite system of unit (CU) consists of an Ångstrom, a proton mass, and a picosecond. They are 1.0e-8 m, 1.6726218e-27 kg, and 1.0e-12 s, respectively.-He insists that it's better to do chemistry in CU than SI.-For example, the attractive force between two Argon atom at the distance of 4Å is:-NaN N-Oops, let's do it polymorphically:-NaN N-I can't do it in SI! On the other hand in CU we can:-9.3407324e-14 N-We compare again:-NaN N-9.3407324e-14 N-Let's optimize the computation by precomputing all the constants.-NaN N-9.3407324e-14 N-We cannot use the default LCSU for calculating constants in this case.-NaN N-NaN N-We must pay attention in which LCSU the constants are computed in.-NaN N-9.3407324e-14 N--}--}
− Tests/Linearity.hs
@@ -1,30 +0,0 @@-{- Test the property of quantity as linear space-   Copyright (c) 2014 Richard Eisenberg--}--module Tests.Linearity where--import Data.Metrology.Poly-import Data.Metrology.Show ()-import Data.Metrology.SI.Poly--import Test.Tasty-import Test.Tasty.HUnit--len1 :: Length SI Rational-len1 = 1 % Meter--linearCompose :: (Fractional a) => a -> a -> Qu d l a  -> Qu d l a -> Qu d l a -linearCompose a b x y = a *| x |+| b *| y---tests :: TestTree-tests = testGroup "Show"-  [ testCase "Identity" $ len1 @?= len1-  , testCase "Addition" $ len1 |+| len1 @?= 2 *| len1 -  , testCase "Summation of multiple quantities" $ -      qSum [len1,len1,len1] @?= 3 *| len1 -  , testCase "Linear composition" $ -      linearCompose 0.2 0.8 len1 len1 @?= len1-  ]-
− Tests/Main.hs
@@ -1,59 +0,0 @@-{- Test/Main.hs--   The units Package-   Copyright (c) 2014 Richard Eisenberg-   eir@cis.upenn.edu--   This is the main testing file for the units package.--}--{-# LANGUAGE ImplicitParams #-}--module Tests.Main where--import qualified Tests.Compile.CGS               ()-import qualified Tests.Compile.EvalType          ()-import qualified Tests.Compile.Lcsu              ()-import qualified Tests.Compile.MetrologySynonyms ()-import qualified Tests.Compile.NoVector          ()-import qualified Tests.Compile.Physics           ()-import qualified Tests.Compile.Quantity          ()-import qualified Tests.Compile.Readme            ()-import qualified Tests.Compile.Simulator         ()-import qualified Tests.Compile.TH                ()-import qualified Tests.Compile.UnitParser        ()-import qualified Tests.Compile.Units             ()--import qualified Tests.Compile.T23               ()--import qualified Tests.Imperial-import qualified Tests.LennardJones-import qualified Tests.Linearity-import qualified Tests.OffSystemAdd-import qualified Tests.OffSystemCSU-import qualified Tests.Parser-import qualified Tests.PhysicalConstants-import qualified Tests.Show-import qualified Tests.Travel-import qualified Tests.Vector--import Test.Tasty--main :: IO ()-main = defaultMain tests--tests :: TestTree-tests =-  let ?epsilon = 0.0000001 in-  testGroup "Tests"-  [ Tests.Imperial.tests-  , Tests.LennardJones.tests-  , Tests.Linearity.tests    -  , Tests.OffSystemAdd.tests-  , Tests.OffSystemCSU.tests-  , Tests.Parser.tests-  , Tests.PhysicalConstants.tests-  , Tests.Show.tests-  , Tests.Travel.tests-  , Tests.Vector.tests    -  ]
− Tests/OffSystemAdd.hs
@@ -1,62 +0,0 @@-{-# LANGUAGE TypeFamilies, NoMonomorphismRestriction #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--module Tests.OffSystemAdd where--import Data.Metrology.Poly-import Data.Metrology.SI-import qualified Data.Dimensions.SI as D--import Test.Tasty-import Test.Tasty.HUnit-import Test.HUnit.Approx--data Foot = Foot-instance Unit Foot where-  type BaseUnit Foot = Meter-  conversionRatio _ = 0.3048--data Year = Year-instance Unit Year where-  type BaseUnit Year = Second-  conversionRatio _ = 60 * 60 * 24 * 365.242--vel1 :: Velocity-vel1 = 1e6 % (Foot :/ Year)--vel2 :: Velocity-vel2 = 0.01 % (Meter :/ Second)---vel1InMS :: Double-vel1InMS = vel1 # (Meter :/ Second)--vel2InMS :: Double-vel2InMS = vel2 # (Meter :/ Second)--vel12InMS :: Double-vel12InMS = (vel1 |+| vel2) # (Meter :/ Second)---len1 :: Length-len1 = 3 % Foot--len2 :: Length-len2 = 1 % Meter--len12InM :: Double-len12InM = (len1 |+| len2) # Meter--type instance DefaultUnitOfDim D.Length = Meter---- The following expression does typecheck,--- because the system is now able to work in defaultLCSU mode--- that only requires relative relation between units.-len12InM' :: Double-len12InM' = (defaultLCSU $ (1 % Meter) |+| (3 % Foot)) # Meter--tests = testGroup "OffSystemAdd"-  [ testCase "vel1inMS" (vel1InMS @?~ 0.00965873546)-  , testCase "vel2inMS" (vel2InMS @?~ 0.01)-  , testCase "vel12inMS" (vel12InMS @?~ 0.01965873)-  , testCase "len12InM" (len12InM @?~ 1.9144) ]
− Tests/OffSystemCSU.hs
@@ -1,36 +0,0 @@-{-# LANGUAGE TypeOperators, DataKinds, TypeFamilies, NoMonomorphismRestriction #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--module Tests.OffSystemCSU where--import Data.Metrology.Poly-import Data.Metrology.SI-import qualified Data.Dimensions.SI as D--import Test.Tasty.HUnit-import Test.HUnit.Approx--type YardPond = MkLCSU '[ (D.Length, Foot)]--type LengthYP = MkQu_DLN D.Length YardPond Double--data Foot = Foot-instance Unit Foot where-  type BaseUnit Foot = Meter-  conversionRatio _ = 0.3048--data Year = Year-instance Unit Year where-  type BaseUnit Year = Second-  conversionRatio _ = 60 * 60 * 24 * 365.242--len1 :: LengthYP-len1 = 3 % Foot --len2 :: LengthYP-len2 = 1 % Meter--x :: Double-x = (len1 |+| len2) # Meter--tests = testCase "OffSystemCSU" (x @?~ 1.9144)
− Tests/Parser.hs
@@ -1,129 +0,0 @@-{- Test the unit parser-   Copyright (c) 2014 Richard Eisenberg--}--{-# LANGUAGE TemplateHaskell #-}--module Tests.Parser where--import Prelude hiding ( lex, exp )--import Data.Metrology.Parser-import Data.Metrology.SI--import Language.Haskell.TH-import Data.Generics--import Test.Tasty-import Test.Tasty.HUnit--leftOnly :: Either a b -> Maybe a-leftOnly (Left a) = Just a-leftOnly (Right _) = Nothing--------------------------------------------------------------------------- TH functions-------------------------------------------------------------------------stripModules :: Data a => a -> a-stripModules = everywhere (mkT (mkName . nameBase))--pprintUnqualified :: (Ppr a, Data a) => a -> String-pprintUnqualified = pprint . stripModules--testSymbolTable :: SymbolTable Name Name-Right testSymbolTable =-   mkSymbolTable (stripModules [ ("k", ''Kilo)-                               , ("da", ''Deca)-                               , ("m", ''Milli)-                               , ("d", ''Deci) ])-                 (stripModules [ ("m", ''Meter)-                               , ("s", ''Second)-                               , ("min", ''Minute)-                               , ("am", ''Ampere) ])--------------------------------------------------------------------------- Overall parser-------------------------------------------------------------------------parseUnitTest :: String -> String-parseUnitTest s =-  case parseUnitExp testSymbolTable s of-    Left _    -> "error"-    Right exp -> pprintUnqualified exp--parseTestCases :: [(String, String)]-parseTestCases =-  [ ("m", "undefined :: Meter")-  , ("s", "undefined :: Second")-  , ("ms", "(:@) (undefined :: Milli) (undefined :: Second)")-  , ("mm", "(:@) (undefined :: Milli) (undefined :: Meter)")-  , ("mmm", "error")-  , ("km", "(:@) (undefined :: Kilo) (undefined :: Meter)")-  , ("m s", "(:*) (undefined :: Meter) (undefined :: Second)")-  , ("m/s", "(:/) (undefined :: Meter) (undefined :: Second)")-  , ("m/s^2", "(:/) (undefined :: Meter) ((:^) (undefined :: Second) (sSucc (sSucc sZero)))")-  , ("s/m m", "(:/) (undefined :: Second) ((:*) (undefined :: Meter) (undefined :: Meter))")-  , ("s s/m m", "(:/) ((:*) (undefined :: Second) (undefined :: Second)) ((:*) (undefined :: Meter) (undefined :: Meter))")-  , ("s*s/m*m", "(:*) ((:/) ((:*) (undefined :: Second) (undefined :: Second)) (undefined :: Meter)) (undefined :: Meter)")-  , ("s*s/(m*m)", "(:/) ((:*) (undefined :: Second) (undefined :: Second)) ((:*) (undefined :: Meter) (undefined :: Meter))")-  , ("m^-1", "(:^) (undefined :: Meter) (sPred sZero)")-  , ("m^(-1)", "(:^) (undefined :: Meter) (sPred sZero)")-  , ("m^(-(1))", "(:^) (undefined :: Meter) (sPred sZero)")-  , ("1", "Number")-  , ("1/s", "(:/) Number (undefined :: Second)")-  , ("m 1 m", "(:*) ((:*) (undefined :: Meter) Number) (undefined :: Meter)")-  , ("  ", "Number")-  , ("", "Number")-  ]--parseUnitTests :: TestTree-parseUnitTests = testGroup "ParseUnit" $-  map (\(str, out) -> testCase ("`" ++ str ++ "'") $ parseUnitTest str @?= out)-    parseTestCases--parseUnitTestT :: String -> String-parseUnitTestT s =-  case parseUnitType testSymbolTable s of-    Left _    -> "error"-    Right exp -> pprintUnqualified exp--parseTestCasesT :: [(String, String)]-parseTestCasesT =-  [ ("m", "Meter")-  , ("s", "Second")-  , ("ms", ":@ Milli Second")-  , ("mm", ":@ Milli Meter")-  , ("mmm", "error")-  , ("km", ":@ Kilo Meter")-  , ("m s", ":* Meter Second")-  , ("m/s", ":/ Meter Second")-  , ("m/s^2", ":/ Meter (:^ Second (Succ (Succ Zero)))")-  , ("s/m m", ":/ Second (:* Meter Meter)")-  , ("s s/m m", ":/ (:* Second Second) (:* Meter Meter)")-  , ("s*s/m*m", ":* (:/ (:* Second Second) Meter) Meter")-  , ("s*s/(m*m)", ":/ (:* Second Second) (:* Meter Meter)")-  , ("m^-1", ":^ Meter (Pred Zero)")-  , ("m^(-1)", ":^ Meter (Pred Zero)")-  , ("m^(-(1))", ":^ Meter (Pred Zero)")-  , ("1", "Number")-  , ("1/s", ":/ Number Second")-  , ("m 1 m", ":* (:* Meter Number) Meter")-  , ("  ", "Number")-  , ("", "Number")-  ]--parseUnitTestsT :: TestTree-parseUnitTestsT = testGroup "ParseUnitType" $-  map (\(str, out) -> testCase ("`" ++ str ++ "'") $ parseUnitTestT str @?= out)-    parseTestCasesT--------------------------------------------------------------------------- Conclusion-------------------------------------------------------------------------tests :: TestTree-tests = testGroup "Parser"-  [ parseUnitTests-  , parseUnitTestsT-  ]
− Tests/PhysicalConstants.hs
@@ -1,112 +0,0 @@-{-# LANGUAGE ConstraintKinds, DataKinds, FlexibleContexts, TypeFamilies,-             TypeOperators, ImplicitParams #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--module Tests.PhysicalConstants where--import Data.Metrology.Poly-import Data.Metrology.Show ()-import Data.Metrology.SI.Poly-import qualified Data.Dimensions.SI as D--import Tests.Compile.MetrologySynonyms--import Test.Tasty.HUnit-import Test.HUnit.Approx--------------------------------------------------------------------- Mass units-------------------------------------------------------------------type instance DefaultUnitOfDim D.Mass = Kilo :@ Gram-type instance DefaultUnitOfDim D.Time = Second-type instance DefaultUnitOfDim D.Length = Meter-type instance DefaultUnitOfDim D.Current = Ampere-type instance DefaultUnitOfDim D.Temperature = Kelvin---- | A unicornhorn of honor (unicornhorn in short) is the historical--- unit of length used in Kingdom of Fantasia. A unicornhorn was--- defined as the length of the horn of the King's honored--- unicorn. Unfortunately, king's men did not documented their--- technology, so today there's no telling how long a unicornhorn was.--data UnicornHorn = UnicornHorn-instance Unit UnicornHorn where-  type BaseUnit UnicornHorn = Canonical-  type DimOfUnit UnicornHorn = D.Length-instance Show UnicornHorn where-  show _ = "uhoh"--type MkQu_UL unit lcsu = MkQu_ULN unit lcsu Double--type KingdomUnit = MkLCSU '[ (D.Length, UnicornHorn) ]--solarMass :: DefaultConvertibleLCSU_D D.Mass l => Mass l Double-solarMass = constant $ 1.98892e33 % Gram--earthMass :: DefaultConvertibleLCSU_D D.Mass l => Mass l Double-earthMass = constant $ 5.9742e24 % Gram--electronMass :: DefaultConvertibleLCSU_D D.Mass l => Mass l Double-electronMass = constant $ 9.10938291e-28 % Gram--protonMass :: DefaultConvertibleLCSU_D D.Mass l => Mass l Double-protonMass = constant $ 1.67262178e-24 % Gram--speedOfLight :: DefaultConvertibleLCSU_D D.Velocity l => Velocity l Double-speedOfLight =  constant $ 299792458 % ((Second :^ sMOne) :* Meter)--elementaryCharge :: DefaultConvertibleLCSU_D D.Charge l => Charge l Double-elementaryCharge = constant $ 1.60217657e-19 % Coulomb--gravitationalConstant :: DefaultConvertibleLCSU_U SIGCUnit l => MkQu_UL SIGCUnit l-gravitationalConstant = constant $ 6.67384e-11 % (undefined :: SIGCUnit)--kB :: DefaultConvertibleLCSU_U SIkBUnit l => MkQu_UL SIkBUnit l-kB = constant $ 1.3806488e-23 % (undefined :: SIkBUnit)---- RAE: problem solved. :)-planckLength :: DefaultConvertibleLCSU_D D.Length l => Length l Double-planckLength = constant $ qSqrt (hbar |*| gravitationalConstant |/| (speedOfLight |^ sThree))--planckTime :: DefaultConvertibleLCSU_D D.Time l => Time l Double-planckTime = constant $ planckLength |/| speedOfLight---- eps0-vacuumPermittivity :: CompatibleUnit l SIPermittivityUnit-  => MkQu_UL SIPermittivityUnit l-vacuumPermittivity =  -  (1 / (4 * pi * 1e-7 * 299792458**2)) % (undefined :: SIPermittivityUnit)--- mu0                     -vacuumPermeability :: CompatibleUnit l SIPermeabilityUnit -  => MkQu_UL SIPermeabilityUnit l-vacuumPermeability = (4 * pi * 1e-7) % (undefined :: SIPermeabilityUnit)---- |Planck constant-planckConstant :: CompatibleUnit l JouleSecond -  => MkQu_UL JouleSecond l-planckConstant =  (6.6260695729e-34) % (undefined :: JouleSecond)---- |Reduced Planck constant-hbar ::  CompatibleUnit l JouleSecond   => MkQu_UL JouleSecond l-hbar = (1 / 2 / pi) *| planckConstant--tests =-  let ?epsilon = 1e-40 in-  testCase "PhysicalConstants" ((planckLength :: Length SI Double) # Meter @?~ 1.616199e-35)--main :: IO ()-main = do-  putStrLn "typechecks!"-  print (planckLength :: Length SI Double)---  print (planckLength :: Length KingdomUnit Double)--- last line does not typecheck -- good!--{- output ----typechecks!-1.616199256057012e-35 m---}--
− Tests/README.md
@@ -1,19 +0,0 @@-`units` Test Design-===================--There are two kinds of test:-- - `Compile` tests test only compilation, not any functionality. A new `Compile`-   test should be placed in the `Compile` directory and imported from-   `Tests.Main`, in alphabetical order with the others.-- - Other tests test both compilation and some functionality. These use the-   [`tasty`](http://hackage.haskell.org/package/tasty) testing framework,-   avaiable on Hackage. Each of these tests should export a -   `tests :: TestTree` definition which contain all the tests in-   the module. Then, this `tests` should be imported and run from within-   `Tests.Main`, following the style there.--To run the tests, just say `cabal test`. You will need to say `git submodule-update --init` to download the contents of `units-defs`, necessary for testing-purposes.
− Tests/Show.hs
@@ -1,24 +0,0 @@-{- Test Show instances-   Copyright (c) 2014 Richard Eisenberg--}--module Tests.Show where--import Data.Metrology-import Data.Metrology.Show ()-import Data.Metrology.SI--import Test.Tasty-import Test.Tasty.HUnit--five :: Double-five = 5--tests :: TestTree-tests = testGroup "Show"-  [ testCase "Meter" $ show (five % Meter) @?= "5.0 m"-  , testCase "Meter/Second" $ show (five % (Meter :/ Second)) @?= "5.0 m/s"-  , testCase "Meter/Second2" $ show (five % (Number :* Second :* Meter :/ (Second :^ sTwo))) @?= "5.0 m/s"-  , testCase "Hertz" $ show (five % Hertz) @?= "5.0 s^-1"-  , testCase "Joule" $ show (five % Joule) @?= "5.0 (kg * m^2)/s^2"-  ]
− Tests/Travel.hs
@@ -1,104 +0,0 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE ImplicitParams #-}--module Tests.Travel where--import Data.Metrology.Poly-import Data.Metrology.SI.Poly--- import Data.Metrology.Imperial.Types (Imperial)--- import Data.Metrology.Imperial.Units-import Data.Units.US (Gallon(..), Mile(..), Pound(..), Yard)-import Data.Metrology.Show ()-import qualified Data.Dimensions.SI as D--import Test.Tasty-import Test.Tasty.HUnit-import Test.HUnit.Approx--type PerArea lcsu n = MkQu_DLN (D.Area :^ MOne) lcsu n---- import the Imperial type from version 1.1 of --- unit-defs/Data.Metrology.Imperial.Types------ The old version seems to have had 1 Gallon be 0.00454609 m^3,--- but version 2.0 of units-defs has 1 Gallon be 231 inch^3------   231 inch^3 = 231 * (0.0254^3) m^3---              = 0.00378542------ and------   0.00454609 / 0.00378542 = 1.200947------ so I use this value to scale the answers below-----gallonChange :: Float-gallonChange = 231 * (0.0254 ** 3) / 0.00454609  --type Imperial =-  MkLCSU-   '[ (D.Length, Yard)-    , (D.Mass, Pound)-    , (D.Time, Second)-    {- Not needed by these tests-    , (D.Current, Ampere)-    , (D.Temperature, Kelvin)-    , (D.AmountOfSubstance, Mole)-    , (D.LuminousIntensity, Candela)-    -}-   ]--fromGLtoED :: MkQu_DLN D.Length Imperial Float-fromGLtoED = 46.5 % Mile--fuelEfficiency :: PerArea Imperial Float-fuelEfficiency = 40 % (Mile :/ Gallon)--gasolineDensity :: MkQu_DLN D.Density Imperial Float-gasolineDensity = 7.29 % (Pound :/ Gallon)--gasolineWeight :: (Fractional f) -  => MkQu_DLN D.Length su f -> PerArea su f -> MkQu_DLN D.Density su f -> MkQu_DLN D.Mass su f-gasolineWeight len0 ef0 den0 = len0 |/| ef0 |*| den0--tests :: TestTree-tests =-  let ?epsilon = 0.00001 in-  testGroup "Travel"-  [ testCase "fromGLtoED" (fromGLtoED # Mile @?~ 46.5)-  , testCase "fuelEfficiency" (fuelEfficiency # (Mile :/ Gallon) @?~ 39.999996)-  , testCase "gasolineDensity" (gasolineDensity # (Pound :/ Gallon) @?~ 7.29)-  , testCase "gasolineWeight" (gasolineWeight fromGLtoED fuelEfficiency gasolineDensity # Pound @?~ 8.474626)-  , testCase "fromGLtoED2" (fromGLtoED # kilo Meter @?~ 74.834496)-  , testCase "fuelEfficiency2" (fuelEfficiency # (kilo Meter :/ Liter) @?~ (14.160248 / gallonChange))-  , testCase "gasolineDensity2" (gasolineDensity # (kilo Gram :/ Liter) @?~ (0.7273698 / gallonChange))-  , testCase "gasolineWeight2" ((gasolineWeight (convert fromGLtoED) (convert fuelEfficiency) (convert gasolineDensity) :: MkQu_DLN D.Mass SI Float) # kilo Gram @?~ 3.8440251) ]--main :: IO ()-main = do-  putStrLn $ fromGLtoED `showIn` Mile-  putStrLn $ fuelEfficiency `showIn` Mile :/ Gallon-  putStrLn $ gasolineDensity `showIn` Pound :/ Gallon-  putStrLn $ show $ gasolineWeight fromGLtoED fuelEfficiency gasolineDensity --  putStrLn ""-  putStrLn $ fromGLtoED `showIn` (kilo Meter)-  putStrLn $ fuelEfficiency `showIn`  kilo Meter :/ Liter-  putStrLn $ gasolineDensity `showIn` kilo Gram :/ Liter-  putStrLn $ show $ (gasolineWeight -    (convert fromGLtoED) (convert fuelEfficiency) (convert gasolineDensity) :: MkQu_DLN D.Mass SI Float)--{---- Execution result ----46.5 mi-39.999996 mi/gal-7.29 lb/gal-8.474626 lb--74.834496 km-14.160248 km/l-0.7273698 kg/l-3.8440251 kg--}
− Tests/Vector.hs
@@ -1,44 +0,0 @@-{-# LANGUAGE TypeFamilies #-}--{- Test the property of vector quantity -   Copyright (c) 2014 Richard Eisenberg--}--module Tests.Vector where--import Data.Metrology.Vector-import Data.Metrology.Show ()-import Data.Metrology.SI.Poly-import Data.VectorSpace--import Test.Tasty-import Test.Tasty.HUnit--len1 :: Length SI Rational-len1 = 1 % Meter---type V2 = Length SI (Rational, Rational)    -vec1 :: V2-vec1 = (2,3) % Meter--linearCompose :: (VectorSpace n, a ~ Scalar n) => a -> a -> Qu d l n  -> Qu d l n -> Qu d l n-linearCompose a b x y = a *| x |+| b *| y---tests :: TestTree-tests = testGroup "Show"-  [ testCase "Identity" $ vec1 @?= vec1-  , testCase "Addition" $ vec1 |+| vec1 @?= 2 *| vec1 -  , testCase "Summation of multiple quantities" $ -      qSum [vec1,vec1,vec1] @?= 3 *| vec1 -  , testCase "Linear composition" $ -      linearCompose 0.2 0.8 vec1 vec1 @?= vec1--  , testCase "Multiplication from right" $ 4 *| vec1 @?= vec1 |* 4-  , testCase "Division by scalar" $ 10 *| vec1 @?= vec1 |/ 0.1--  , testCase "scalar product" $-      (5 % Meter) |*^| vec1 @?= ((10, 15) % (Meter :^ sTwo))-  ]-
− units-defs/Data/Constants/Math.hs
@@ -1,19 +0,0 @@--------------------------------------------------------------------------------- |--- Module      :  Data.Constants.Math--- Copyright   :  (C) 2014 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ Approximates mathematical constants as 'Rational's--------------------------------------------------------------------------------module Data.Constants.Math where--piR :: Rational-piR = 3.1415926535897932384626433832795028841971693993751058209749445923078164--eR :: Rational-eR = 2.71828182845904523536028747135266249775724709369995957496696762772407663
− units-defs/Data/Constants/Mechanics.hs
@@ -1,26 +0,0 @@-{-# LANGUAGE TypeOperators, ConstraintKinds, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Constants.Mechanics--- Copyright   :  (C) 2014 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This file defines dimensioned physical constants, useful in mechanics.------ The names used are a short description of the constant followed by its--- usual symbol, separated by an underscore. For non-Latin symbols, the--- Latin-lettered transliteration of the symbol name is used.--------------------------------------------------------------------------------module Data.Constants.Mechanics where--import Data.Metrology.Poly-import Data.Metrology.SI.Poly-import Data.Metrology.TH---- | Acceleration at Earth's surface due to gravity.-declareConstant "gravity_g" 9.80665 [t| Meter :/ Second :^ Two |]
− units-defs/Data/Dimensions/SI.hs
@@ -1,60 +0,0 @@-{-# LANGUAGE TypeOperators, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Dimensions.SI--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines SI dimensions. The names of SI dimensions conform to--- <http://www.bipm.org/utils/common/documents/jcgm/JCGM_200_2012.pdf>.--------------------------------------------------------------------------------module Data.Dimensions.SI where--import Data.Metrology.Poly-import Data.Metrology.TH--declareDimension "Length"-declareDimension "Mass"-declareDimension "Time"-declareDimension "Current"-declareDimension "Temperature"-declareDimension "AmountOfSubstance"-declareDimension "LuminousIntensity"--type Area                = Length            :^ Two-type Volume              = Length            :^ Three-type Velocity            = Length            :/ Time-type Acceleration        = Velocity          :/ Time-type Wavenumber          = Length            :^ MOne-type Density             = Mass              :/ Volume-type SurfaceDensity      = Mass              :/ Area-type SpecificVolume      = Volume            :/ Mass-type CurrentDensity      = Current           :/ Area-type MagneticStrength    = Current           :/ Length-type Concentration       = AmountOfSubstance          :/ Volume-type Luminance           = LuminousIntensity        :/ Area--type Frequency           = Time              :^ MOne-type Force               = Mass              :* Acceleration-type Pressure            = Force             :/ Area-type Energy              = Force             :* Length-type Power               = Energy            :/ Time-type Charge              = Current           :* Time-type ElectricPotential   = Power             :/ Current-type Capacitance         = Charge            :/ ElectricPotential-type Resistance          = ElectricPotential :/ Current-type Conductance         = Current           :/ ElectricPotential-type MagneticFlux        = ElectricPotential :* Time-type MagneticFluxDensity = MagneticFlux      :/ Area-type Inductance          = MagneticFlux      :/ Current-type LuminousFlux        = LuminousIntensity-type Illuminance         = LuminousIntensity :/ Area-type Kerma               = Area              :/ (Time :^ Two)-type CatalyticActivity   = AmountOfSubstance :/ Time--type Momentum            = Mass              :* Velocity
− units-defs/Data/Metrology/SI.hs
@@ -1,23 +0,0 @@--------------------------------------------------------------------------------- |--- Module      :  Data.Metrology.SI--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module exports unit, type, and prefix definitions according to the SI--- system of units. The definitions were taken from here:--- <http://www.bipm.org/en/si/> and here:--- <http://www.bipm.org/utils/common/documents/jcgm/JCGM_200_2012.pdf>.------ This module exports the monomorphic version of the definitions. For--- polymorphic versions, use 'Data.Metrology.SI.Poly'.--------------------------------------------------------------------------------module Data.Metrology.SI (-  module Data.Metrology.SI.Mono,-  ) where--import Data.Metrology.SI.Mono
− units-defs/Data/Metrology/SI/Mono.hs
@@ -1,40 +0,0 @@-{-# LANGUAGE TypeOperators, TypeFamilies #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Metrology.SI.Mono--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module exports definitions for the SI system, with the intent--- of using these definitions in a monomorphic manner -- that is,--- with the DefaultLCSU. The difference between this module and--- 'Data.Metrology.SI.MonoTypes' is that this module also exports--- instances of 'DefaultUnitOfDim', necessary for use with--- 'DefaultLCSU'.--------------------------------------------------------------------------------module Data.Metrology.SI.Mono (-  module Data.Metrology.SI.MonoTypes,-  module Data.Units.SI,-  module Data.Units.SI.Prefixes,-  module Data.Units.SI.Parser-  ) where--import Data.Metrology.SI.MonoTypes-import Data.Units.SI-import Data.Units.SI.Prefixes-import qualified Data.Dimensions.SI as D-import Data.Metrology-import Data.Units.SI.Parser--type instance DefaultUnitOfDim D.Length            = Meter-type instance DefaultUnitOfDim D.Mass              = Kilo :@ Gram-type instance DefaultUnitOfDim D.Time              = Second-type instance DefaultUnitOfDim D.Current           = Ampere-type instance DefaultUnitOfDim D.Temperature       = Kelvin-type instance DefaultUnitOfDim D.AmountOfSubstance = Mole-type instance DefaultUnitOfDim D.LuminousIntensity = Lumen
− units-defs/Data/Metrology/SI/MonoTypes.hs
@@ -1,59 +0,0 @@-{-# LANGUAGE TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Metrology.SI.MonoTypes--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines type synonyms for SI units, using a Double as the--- internal representation. This module /does not/ export instances of--- 'DefaultUnitOfDim'. Use 'Data.Metrology.SI.Mono' for that.--------------------------------------------------------------------------------module Data.Metrology.SI.MonoTypes where--import Data.Metrology-import qualified Data.Dimensions.SI as D--type Length              = MkQu_D D.Length-type Mass                = MkQu_D D.Mass-type Time                = MkQu_D D.Time-type Current             = MkQu_D D.Current-type Temperature         = MkQu_D D.Temperature-type AmountOfSubstance   = MkQu_D D.AmountOfSubstance-type LuminousIntensity   = MkQu_D D.LuminousIntensity--type Area                = MkQu_D D.Area-type Volume              = MkQu_D D.Volume-type Velocity            = MkQu_D D.Velocity-type Acceleration        = MkQu_D D.Acceleration-type Wavenumber          = MkQu_D D.Wavenumber-type Density             = MkQu_D D.Density-type SurfaceDensity      = MkQu_D D.SurfaceDensity-type SpecificVolume      = MkQu_D D.SpecificVolume-type CurrentDensity      = MkQu_D D.CurrentDensity-type MagneticStrength    = MkQu_D D.MagneticStrength-type Concentration       = MkQu_D D.Concentration-type Luminance           = MkQu_D D.Luminance-type Frequency           = MkQu_D D.Frequency-type Force               = MkQu_D D.Force-type Pressure            = MkQu_D D.Pressure-type Energy              = MkQu_D D.Energy-type Power               = MkQu_D D.Power-type Charge              = MkQu_D D.Charge-type ElectricPotential   = MkQu_D D.ElectricPotential-type Capacitance         = MkQu_D D.Capacitance-type Resistance          = MkQu_D D.Resistance-type Conductance         = MkQu_D D.Conductance-type MagneticFlux        = MkQu_D D.MagneticFlux-type MagneticFluxDensity = MkQu_D D.MagneticFluxDensity-type Inductance          = MkQu_D D.Inductance-type LuminousFlux        = MkQu_D D.LuminousFlux-type Illuminance         = MkQu_D D.Illuminance-type Kerma               = MkQu_D D.Kerma-type CatalyticActivity   = MkQu_D D.CatalyticActivity-type Momentum            = MkQu_D D.Momentum
− units-defs/Data/Metrology/SI/Poly.hs
@@ -1,39 +0,0 @@-{-# LANGUAGE TypeOperators, DataKinds #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Metrology.SI.Poly--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module exports definitions for the SI system, with the intent--- of using these definitions in a polymorphic manner -- that is,--- with multiple LCSUs.--------------------------------------------------------------------------------module Data.Metrology.SI.Poly (-  SI,-  module Data.Metrology.SI.PolyTypes,-  module Data.Units.SI.Prefixes,-  module Data.Units.SI,-  module Data.Units.SI.Parser-  ) where--import Data.Metrology.SI.PolyTypes-import Data.Units.SI.Prefixes-import Data.Units.SI-import qualified Data.Dimensions.SI as D-import Data.Metrology-import Data.Units.SI.Parser--type SI = MkLCSU '[ (D.Length, Meter)-                  , (D.Mass, Kilo :@ Gram)-                  , (D.Time, Second)-                  , (D.Current, Ampere)-                  , (D.Temperature, Kelvin)-                  , (D.AmountOfSubstance, Mole)-                  , (D.LuminousIntensity, Lumen)-                  ]
− units-defs/Data/Metrology/SI/PolyTypes.hs
@@ -1,58 +0,0 @@-{-# LANGUAGE TypeOperators, DataKinds #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Metrology.SI.PolyTypes--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines type synonyms for dimensions based on the seven--- SI dimensions, for arbitrary choice of system of units and numerical values.--------------------------------------------------------------------------------module Data.Metrology.SI.PolyTypes where--import Data.Metrology-import qualified Data.Dimensions.SI as D--type Length              = MkQu_DLN D.Length              -type Mass                = MkQu_DLN D.Mass                -type Time                = MkQu_DLN D.Time                -type Current             = MkQu_DLN D.Current             -type Temperature         = MkQu_DLN D.Temperature         -type AmountOfSubstance   = MkQu_DLN D.AmountOfSubstance   -type LuminousIntensity   = MkQu_DLN D.LuminousIntensity   --type Area                = MkQu_DLN D.Area                -type Volume              = MkQu_DLN D.Volume              -type Velocity            = MkQu_DLN D.Velocity            -type Acceleration        = MkQu_DLN D.Acceleration        -type Wavenumber          = MkQu_DLN D.Wavenumber          -type Density             = MkQu_DLN D.Density             -type SurfaceDensity      = MkQu_DLN D.SurfaceDensity      -type SpecificVolume      = MkQu_DLN D.SpecificVolume      -type CurrentDensity      = MkQu_DLN D.CurrentDensity      -type MagneticStrength    = MkQu_DLN D.MagneticStrength    -type Concentration       = MkQu_DLN D.Concentration       -type Luminance           = MkQu_DLN D.Luminance           -type Frequency           = MkQu_DLN D.Frequency           -type Force               = MkQu_DLN D.Force               -type Pressure            = MkQu_DLN D.Pressure            -type Energy              = MkQu_DLN D.Energy              -type Power               = MkQu_DLN D.Power               -type Charge              = MkQu_DLN D.Charge              -type ElectricPotential   = MkQu_DLN D.ElectricPotential   -type Capacitance         = MkQu_DLN D.Capacitance         -type Resistance          = MkQu_DLN D.Resistance          -type Conductance         = MkQu_DLN D.Conductance         -type MagneticFlux        = MkQu_DLN D.MagneticFlux        -type MagneticFluxDensity = MkQu_DLN D.MagneticFluxDensity -type Inductance          = MkQu_DLN D.Inductance          -type LuminousFlux        = MkQu_DLN D.LuminousFlux        -type Illuminance         = MkQu_DLN D.Illuminance         -type Kerma               = MkQu_DLN D.Kerma               -type CatalyticActivity   = MkQu_DLN D.CatalyticActivity   -type Momentum            = MkQu_DLN D.Momentum            
− units-defs/Data/Units/CGS.hs
@@ -1,56 +0,0 @@-{-# LANGUAGE PatternSynonyms, TemplateHaskell, TypeOperators,-             TypeFamilies #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.CGS--- Copyright   :  (C) 2014 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines units used in the centimeter/gram/second system--- of measurement.------ Included are all mechanical units mentioned here:--- http://en.wikipedia.org/wiki/Centimetre%E2%80%93gram%E2%80%93second_system_of_units------ Some electromagnetic units are not included, because these do not have--- reliable conversions to/from the SI units, on which the @units-defs@--- edifice is based.--------------------------------------------------------------------------------module Data.Units.CGS (-  Centi(..), centi, Meter(..), pattern Metre, Gram(..), Second(..),-  module Data.Units.CGS-  ) where--import Data.Units.SI-import Data.Units.SI.Prefixes-import Data.Metrology.Poly-import Data.Metrology.TH--type Centimeter = Centi :@ Meter-pattern Centimeter = Centi :@ Meter--type Centimetre = Centimeter-pattern Centimetre = Centimeter--declareDerivedUnit "Gal"-  [t| Centimeter :/ Second :^ Two |]                1 (Just "Gal")-declareDerivedUnit "Dyne"-  [t| Gram :* Centimeter :/ Second :^ Two |]        1 (Just "dyn")-declareDerivedUnit "Erg"-  [t| Gram :* Centimeter :^ Two :/ Second :^ Two |] 1 (Just "erg")-declareDerivedUnit "Barye"-  [t| Gram :/ (Centimeter :* Second :^ Two) |]      1 (Just "Ba")-declareDerivedUnit "Poise"-  [t| Gram :/ (Centimeter :* Second) |]             1 (Just "P")-declareDerivedUnit "Stokes"-  [t| Centimeter :^ Two :/ Second |]                1 (Just "St")-declareDerivedUnit "Kayser"-  [t| Centimeter :^ MOne |]                         1 Nothing--declareDerivedUnit "Maxwell" [t| Nano :@ Weber |]  10  (Just "Mx")-declareDerivedUnit "Gauss"   [t| Milli :@ Tesla |] 0.1 (Just "G")
− units-defs/Data/Units/PreciousMetals.hs
@@ -1,28 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Metrology.Units.PreciousMetals--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ Units used in the measure of precious metals.--------------------------------------------------------------------------------module Data.Units.PreciousMetals where--import Data.Metrology-import Data.Metrology.TH-import Data.Units.SI-import Data.Units.SI.Prefixes--import qualified Data.Units.US.Avoirdupois as Avdp-import qualified Data.Units.US.Troy        as Troy--declareDerivedUnit "Carat"    [t| Milli :@ Gram |] 200  (Just "carat")-declareDerivedUnit "Point"    [t| Carat         |] 0.01 (Just "point")-declareDerivedUnit "AssayTon" [t| (Milli :@ Gram) :* (Avdp.Ton :/ Troy.Ounce) |]-                              1 (Just "AT")
− units-defs/Data/Units/SI.hs
@@ -1,106 +0,0 @@-{-# LANGUAGE TypeFamilies, TypeOperators, PatternSynonyms, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.SI--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module exports unit definitions according to the SI system of units.--- The definitions were taken from here: <http://www.bipm.org/en/si/>.------ Some additional units were added based on--- <http://www.bipm.org/en/si/si_brochure/chapter4/table6.html this link>:--- "Non-SI units accepted for use with the SI,--- and units based on fundamental constants".------ There is one deviation from the definitions at that site: To work better--- with prefixes, the unit of mass is 'Gram'.------ This module exports both American spellings and British spellings of--- units, using pattern synonyms to get the British spellings of data--- constructors.--------------------------------------------------------------------------------module Data.Units.SI where--import Data.Metrology.Poly-import Data.Metrology.TH-import Data.Dimensions.SI-import Data.Units.SI.Prefixes ( Kilo, Centi )--import Language.Haskell.TH ( Name )--declareCanonicalUnit "Meter"   [t| Length |]                         (Just "m")--type Metre = Meter-pattern Metre = Meter--declareCanonicalUnit "Gram"    [t| Mass |]                           (Just "g")--type Gramme = Gram-pattern Gramme = Gram--declareCanonicalUnit "Second"  [t| Time |]                           (Just "s")---- | Derived SI unit-declareDerivedUnit "Minute"    [t| Second |]                    60   (Just "min")---- | Derived SI unit-declareDerivedUnit "Hour"      [t| Minute |]                    60   (Just "h")--declareCanonicalUnit "Ampere"  [t| Current |]                        (Just "A")-declareCanonicalUnit "Kelvin"  [t| Temperature |]                    (Just "K")-declareCanonicalUnit "Mole"    [t| AmountOfSubstance |]              (Just "mol")-declareCanonicalUnit "Candela" [t| LuminousIntensity |]              (Just "cd")--declareDerivedUnit "Hertz"     [t| Number :/ Second |]          1    (Just "Hz")---- | This is not in the SI standard, but is used widely.-declareDerivedUnit "Liter"     [t| (Centi :@ Meter) :^ Three |] 1000 (Just "L")--type Litre = Liter-pattern Litre = Liter--declareDerivedUnit "Newton"    [t| Gram :* Meter :/ (Second :^ Two) |]  1000  (Just "N")-declareDerivedUnit "Pascal"    [t| Newton :/ (Meter :^ Two) |]          1     (Just "Pa")-declareDerivedUnit "Joule"     [t| Newton :* Meter |]                   1     (Just "J")-declareDerivedUnit "Watt"      [t| Joule :/ Second |]                   1     (Just "W")-declareDerivedUnit "Coulomb"   [t| Ampere :* Second |]                  1     (Just "C")-declareDerivedUnit "Volt"      [t| Watt :/ Ampere |]                    1     (Just "V")-declareDerivedUnit "Farad"     [t| Coulomb :/ Volt |]                   1     (Just "F")-declareDerivedUnit "Ohm"       [t| Volt :/ Ampere |]                    1     (Just "Ω")-declareDerivedUnit "Siemens"   [t| Ampere :/ Volt |]                    1     (Just "S")-declareDerivedUnit "Weber"     [t| Volt :* Second |]                    1     (Just "Wb")-declareDerivedUnit "Tesla"     [t| Weber :/ (Meter :^ Two) |]           1     (Just "T")-declareDerivedUnit "Henry"     [t| Weber :/ Ampere |]                   1     (Just "H")-declareDerivedUnit "Lumen"     [t| Candela |]                           1     (Just "lm")-declareDerivedUnit "Lux"       [t| Lumen :/ (Meter :^ Two) |]           1     (Just "lx")-declareDerivedUnit "Becquerel" [t| Number :/ Second |]                  1     (Just "Bq")-declareDerivedUnit "Gray"      [t| (Meter :^ Two) :/ (Second :^ Two) |] 1     (Just "Gy")-declareDerivedUnit "Sievert"   [t| (Meter :^ Two) :/ (Second :^ Two) |] 1     (Just "Sv")-declareDerivedUnit "Katal"     [t| Mole :/ Second |]                    1     (Just "kat")---- | Derived SI unit-declareDerivedUnit "Hectare"   [t| Meter :^ Two |]                      10000 (Just "ha")---- | Derived SI unit-declareDerivedUnit "Ton"       [t| Kilo :@ Gram |]                      1000  (Just "t")--type Tonne = Ton-pattern Tonne = Ton---- | A list of the names of all unit types. Useful with--- 'Data.Metrology.Parser.makeQuasiQuoter'.-siUnits :: [Name]-siUnits =-  [ ''Meter, ''Gram, ''Second, ''Minute, ''Hour, ''Ampere-  , ''Kelvin, ''Mole, ''Candela, ''Hertz, ''Liter, ''Newton, ''Pascal-  , ''Joule, ''Watt, ''Coulomb, ''Volt, ''Farad, ''Ohm, ''Siemens-  , ''Weber, ''Tesla, ''Henry, ''Lumen, ''Lux, ''Becquerel, ''Gray-  , ''Sievert, ''Katal, ''Hectare, ''Ton-  ]-    
− units-defs/Data/Units/SI/Parser.hs
@@ -1,29 +0,0 @@-{-# LANGUAGE TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.SI.Parser--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ Defines a quasi-quoting parser for unit expressions. Writing, say,--- @[si| m/s^2 |]@ produces @(Meter :/ (Second :^ sTwo))@. A larger--- example is------ > ke :: Energy--- > ke = 5 % [si| N km |]  -- 5 Newton-kilometers------ See `Data.Metrology.Parser` for more information about the syntax--- of these unit expressions.--------------------------------------------------------------------------------module Data.Units.SI.Parser ( si ) where--import Data.Metrology.Parser-import Data.Units.SI.Prefixes-import Data.Units.SI--makeQuasiQuoter "si" siPrefixes siUnits
− units-defs/Data/Units/SI/Prefixes.hs
@@ -1,227 +0,0 @@-{-# LANGUAGE TypeOperators, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.SI.Prefixes--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ Defines prefixes from the SI standard at <http://www.bipm.org/en/si/>--------------------------------------------------------------------------------module Data.Units.SI.Prefixes where--import Language.Haskell.TH ( Name )-import Data.Metrology.Poly---- | 10^1-data Deca = Deca-instance UnitPrefix Deca where-  multiplier _ = 1e1-instance Show Deca where-  show _ = "da"--deca :: unit -> Deca :@ unit-deca = (Deca :@)---- | 10^2-data Hecto = Hecto-instance UnitPrefix Hecto where-  multiplier _ = 1e2-instance Show Hecto where-  show _ = "h"--hecto :: unit -> Hecto :@ unit-hecto = (Hecto :@)---- | 10^3-data Kilo = Kilo-instance UnitPrefix Kilo where-  multiplier _ = 1e3-instance Show Kilo where-  show _ = "k"--kilo :: unit -> Kilo :@ unit-kilo = (Kilo :@)---- | 10^6-data Mega = Mega-instance UnitPrefix Mega where-  multiplier _ = 1e6-instance Show Mega where-  show _ = "M"--mega :: unit -> Mega :@ unit-mega = (Mega :@)---- | 10^9-data Giga = Giga-instance UnitPrefix Giga where-  multiplier _ = 1e9-instance Show Giga where-  show _ = "G"--giga :: unit -> Giga :@ unit-giga = (Giga :@)---- | 10^12-data Tera = Tera-instance UnitPrefix Tera where-  multiplier _ = 1e12-instance Show Tera where-  show _ = "T"--tera :: unit -> Tera :@ unit-tera = (Tera :@)---- | 10^15-data Peta = Peta-instance UnitPrefix Peta where-  multiplier _ = 1e15-instance Show Peta where-  show _ = "P"--peta :: unit -> Peta :@ unit-peta = (Peta :@)---- | 10^18-data Exa = Exa-instance UnitPrefix Exa where-  multiplier _ = 1e18-instance Show Exa where-  show _ = "E"--exa :: unit -> Exa :@ unit-exa = (Exa :@)---- | 10^21-data Zetta = Zetta-instance UnitPrefix Zetta where-  multiplier _ = 1e21-instance Show Zetta where-  show _ = "Z"--zetta :: unit -> Zetta :@ unit-zetta = (Zetta :@)---- | 10^24-data Yotta = Yotta-instance UnitPrefix Yotta where-  multiplier _ = 1e24-instance Show Yotta where-  show _ = "Y"--yotta :: unit -> Yotta :@ unit-yotta = (Yotta :@)---- | 10^-1-data Deci = Deci-instance UnitPrefix Deci where-  multiplier _ = 1e-1-instance Show Deci where-  show _ = "d"--deci :: unit -> Deci :@ unit-deci = (Deci :@)---- | 10^-2-data Centi = Centi-instance UnitPrefix Centi where-  multiplier _ = 1e-2-instance Show Centi where-  show _ = "c"--centi :: unit -> Centi :@ unit-centi = (Centi :@)---- | 10^-3-data Milli = Milli-instance UnitPrefix Milli where-  multiplier _ = 1e-3-instance Show Milli where-  show _ = "m"--milli :: unit -> Milli :@ unit-milli = (Milli :@)---- | 10^-6-data Micro = Micro-instance UnitPrefix Micro where-  multiplier _ = 1e-6-instance Show Micro where-  show _ = "μ"--micro :: unit -> Micro :@ unit-micro = (Micro :@)---- | 10^-9-data Nano = Nano-instance UnitPrefix Nano where-  multiplier _ = 1e-9-instance Show Nano where-  show _ = "n"--nano :: unit -> Nano :@ unit-nano = (Nano :@)---- | 10^-12-data Pico = Pico-instance UnitPrefix Pico where-  multiplier _ = 1e-12-instance Show Pico where-  show _ = "p"--pico :: unit -> Pico :@ unit-pico = (Pico :@)---- | 10^-15-data Femto = Femto-instance UnitPrefix Femto where-  multiplier _ = 1e-15-instance Show Femto where-  show _ = "f"--femto :: unit -> Femto :@ unit-femto = (Femto :@)---- | 10^-18-data Atto = Atto-instance UnitPrefix Atto where-  multiplier _ = 1e-18-instance Show Atto where-  show _ = "a"--atto :: unit -> Atto :@ unit-atto = (Atto :@)---- | 10^-21-data Zepto = Zepto-instance UnitPrefix Zepto where-  multiplier _ = 1e-21-instance Show Zepto where-  show _ = "z"--zepto :: unit -> Zepto :@ unit-zepto = (Zepto :@)---- | 10^-24-data Yocto = Yocto-instance UnitPrefix Yocto where-  multiplier _ = 1e-24-instance Show Yocto where-  show _ = "y"--yocto :: unit -> Yocto :@ unit-yocto = (Yocto :@)---- | A list of the names of all prefix types. Useful with--- 'Data.Metrology.Parser.makeQuasiQuoter'.-siPrefixes :: [Name]-siPrefixes =-  [ ''Deca, ''Hecto, ''Kilo, ''Mega, ''Giga, ''Tera, ''Peta, ''Exa-  , ''Zetta, ''Yotta, ''Deci, ''Centi, ''Milli, ''Micro, ''Nano-  , ''Pico, ''Femto, ''Atto, ''Zepto, ''Yocto-  ]
− units-defs/Data/Units/US.hs
@@ -1,62 +0,0 @@--------------------------------------------------------------------------------- |--- Module      :  Data.Units.US--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines the American customary system of units. Because--- there are some names that are conflicted, even within this system,--- there are several modules underneath here, defining sub-parts of--- the US system. This module gathers together a subjective set of--- units users will commonly wish to use. It also exports type instances--- 'DefaultUnitOfDim' that use the /SI/ internal representations. This--- choice is made for inter-compatibility with SI computations. If you--- want the foot-pound-second system, use the 'FPS'.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US (-  -- * Lengths-  Angstrom(..), Mil(..), Point(..), Pica(..),-  Inch(..), Foot(..), Yard(..), Mile(..), NauticalMile(..),--  -- * Velocity-  Knot(..),-  -  -- * Area-  Survey.Acre(..),--  -- * Volume-  -- | These are all /liquid/ measures. Solid measures are /different/.-  Liq.Teaspoon(..), Liq.Tablespoon(..), Liq.FluidOunce(..),-  Liq.Cup(..), Liq.Pint(..), Liq.Quart(..), Liq.Gallon(..),--  -- * Mass-  -- | These are all in the avoirdupois system-  Avdp.Ounce(..), Avdp.Pound(..), Avdp.Ton(..),--  -- * Pressure-  Atmosphere(..), Bar(..),--  -- * Energy-  FoodCalorie(..), Therm(..), Btu(..),--  -- * Power-  Horsepower(..)-  ) where--import Data.Units.US.Misc-import qualified Data.Units.US.Survey      as Survey-import qualified Data.Units.US.Liquid      as Liq-import qualified Data.Units.US.Avoirdupois as Avdp
− units-defs/Data/Units/US/Apothecaries.hs
@@ -1,46 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.Apothecaries--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines apothecaries' measures of mass. These measures--- are rarely used.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.Apothecaries (-  module Data.Units.US.Apothecaries,--  -- | The apothecaries' grain is the same as the avoirdupois grain.-  Grain(..),--  -- | The apothecaries' ounce and pound are the troy ounce and pound.-  Ounce(..), Pound(..)-  ) where--import Data.Metrology.TH-import Data.Units.US.Avoirdupois ( Grain(..) )-import Data.Units.US.Troy ( Ounce(..), Pound(..) )--import Language.Haskell.TH--declareDerivedUnit "Scruple" [t| Grain |] 20   (Just "sap")-declareDerivedUnit "Dram"    [t| Grain |] 60   (Just "drap")---- | Includes 'Grain', 'Scruple', 'Dram', 'Ounce', and 'Pound'.-apothecariesMassMeasures :: [Name]-apothecariesMassMeasures = [ ''Grain, ''Scruple, ''Dram, ''Ounce, ''Pound ]
− units-defs/Data/Units/US/Avoirdupois.hs
@@ -1,50 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.Avoirdupois--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines avoirdupois measures of mass. The avoirdupois--- system is the one most commonly used in the US.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.Avoirdupois where--import Data.Metrology.TH-import Data.Units.SI ( Gram )--import Language.Haskell.TH--declareDerivedUnit "Pound"             [t| Gram  |] 453.59237    (Just "lb")--declareDerivedUnit "Grain"             [t| Pound |] (1/7000)     (Just "gr")-declareDerivedUnit "Dram"              [t| Grain |] (27 + 11/32) (Just "dr")-declareDerivedUnit "Ounce"             [t| Pound |] (1/16)       (Just "oz")-declareDerivedUnit "Hundredweight"     [t| Pound |] 100          (Just "cwt")-declareDerivedUnit "LongHundredweight" [t| Pound |] 112          (Just "longcwt")-declareDerivedUnit "Ton"               [t| Pound |] 2000         (Just "ton")-declareDerivedUnit "LongTon"           [t| Pound |] 2240         (Just "longton")---- | Includes 'Ounce', 'Pound', 'Ton'-commonMassMeasures :: [Name]-commonMassMeasures = [ ''Ounce, ''Pound, ''Ton]---- | Includes 'Grain', 'Dram', 'Hundredweight', 'LongHundredweight',--- and 'LongTon'-otherMassMeasures :: [Name]-otherMassMeasures = [ ''Grain, ''Dram, ''Hundredweight, ''LongHundredweight-                    , ''LongTon ]
− units-defs/Data/Units/US/DryVolume.hs
@@ -1,47 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.DryVolume--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines dry volume measures as used in the USA.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.DryVolume where--import Data.Metrology-import Data.Metrology.TH-import Data.Units.US.Misc--import Language.Haskell.TH--declareDerivedUnit "Gallon"      [t| Inch :^ Three |] 268.8025 (Just "gal")-declareDerivedUnit "Quart"       [t| Gallon        |] (1/4)    (Just "qt")-declareDerivedUnit "Pint"        [t| Quart         |] (1/2)    (Just "pt")-declareDerivedUnit "Peck"        [t| Gallon        |] 2        (Just "pk")-declareDerivedUnit "Bushel"      [t| Peck          |] 4        (Just "bu")-declareDerivedUnit "Barrel"      [t| Inch :^ Three |] 7056     (Just "bbl")-declareDerivedUnit "Cord"        [t| Foot :^ Three |] 128      (Just "cd")-declareDerivedUnit "BoardFoot"   [t| Foot :^ Three |] (1/12)   (Just "FBM")-declareDerivedUnit "RegisterTon" [t| Foot :^ Three |] 100      (Just "RT")--declareDerivedUnit "CranberryBarrel" [t| Inch :^ Three |] 5826 (Just "bbl")---- | Includes all measures in this file, except 'CranberryBarrel'.-dryVolumeMeasures :: [Name]-dryVolumeMeasures = [ ''Pint, ''Quart, ''Gallon, ''Peck, ''Bushel-                    , ''Barrel, ''Cord, ''BoardFoot, ''RegisterTon ]
− units-defs/Data/Units/US/Liquid.hs
@@ -1,60 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.Liquid--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines liquid volume measures as used in the USA.--- Note that liquid volumes in the USA differ both from solid volumes--- in the USA and from liquid volumes in the UK.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.Liquid where--import Data.Metrology-import Data.Metrology.TH-import Data.Units.US.Misc--import Language.Haskell.TH--declareDerivedUnit "Gallon"     [t| Inch :^ Three |] 231     (Just "gal")--declareDerivedUnit "FluidOunce" [t| Gallon        |] (1/128) (Just "floz")-declareDerivedUnit "Gill"       [t| FluidOunce    |] 4       (Just "gi")-declareDerivedUnit "Cup"        [t| FluidOunce    |] 8       (Just "cp")-declareDerivedUnit "Pint"       [t| FluidOunce    |] 16      (Just "pt")-declareDerivedUnit "Quart"      [t| Gallon        |] (1/4)   (Just "qt")--declareDerivedUnit "Teaspoon"   [t| FluidOunce    |] (1/6)   (Just "tsp")-declareDerivedUnit "Tablespoon" [t| Teaspoon      |] 3       (Just "Tbsp")-declareDerivedUnit "Shot"       [t| Tablespoon    |] 3       (Just "jig")-declareDerivedUnit "Minim"      [t| Teaspoon      |] (1/80)  (Just "min")-declareDerivedUnit "Dram"       [t| Minim         |] 60      (Just "fldr")--declareDerivedUnit "Hogshead"   [t| Gallon        |] 63      (Just "hogshead")-declareDerivedUnit "Barrel"     [t| Hogshead      |] (1/2)   (Just "bbl")-declareDerivedUnit "OilBarrel"  [t| Gallon        |] 42      (Just "bbl")---- | As shown on Wikipedia: http://en.wikipedia.org/wiki/United_States_customary_units-commonLiquidMeasures :: [Name]-commonLiquidMeasures = [ ''Teaspoon, ''Tablespoon, ''FluidOunce, ''Cup, ''Pint-                       , ''Quart, ''Gallon ]---- | Includes the rest of the measures in this file.-otherLiquidMeasures :: [Name]-otherLiquidMeasures = [ ''Minim, ''Dram, ''Shot, ''Gill, ''Barrel-                      , ''OilBarrel, ''Hogshead ]
− units-defs/Data/Units/US/Misc.hs
@@ -1,85 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.Misc--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines American customary units that don't fit into--- other categories.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.Misc (-  module Data.Units.US.Misc,-  Maxwell(..)-  ) where--import Data.Metrology-import Data.Metrology.TH--import Data.Units.SI-import Data.Units.SI.Prefixes-import Data.Units.CGS-import Data.Constants.Math--import Language.Haskell.TH--declareDerivedUnit "Foot"       [t| Meter         |] 0.3048    (Just "ft")-declareDerivedUnit "Inch"       [t| Foot          |] (1/12)    (Just "in")-declareDerivedUnit "Yard"       [t| Foot          |] 3         (Just "yd")-declareDerivedUnit "Mile"       [t| Foot          |] 5280      (Just "mi")-declareDerivedUnit "Angstrom"   [t| Nano :@ Meter |] 0.1       (Just "Å")-declareDerivedUnit "Hand"       [t| Inch          |] 4         (Just "hand")-declareDerivedUnit "Mil"        [t| Inch          |] 0.001     (Just "mil")--declareDerivedUnit "Point"      [t| Inch   |] 0.013837    (Just "p")-declareDerivedUnit "Pica"       [t| Point  |] 12          (Just "P")--declareDerivedUnit "Fathom"       [t| Yard       |]    2     (Just "ftm")-declareDerivedUnit "Cable"        [t| Fathom     |]    120   (Just "cb")-declareDerivedUnit "NauticalMile" [t| Kilo :@ Meter |] 1.852 (Just "NM")--declareDerivedUnit "Knot"       [t| NauticalMile :/ Hour |] 1 (Just "kn")--declareDerivedUnit "Atmosphere" [t| Kilo :@ Pascal |]  101.325 (Just "atm")-declareDerivedUnit "Bar"        [t| Kilo :@ Pascal |]  100     (Just "bar")-declareDerivedUnit "MillimeterOfMercury"-                                [t| Pascal |] 133.322387415 (Just "mmHg")-declareDerivedUnit "Torr"       [t| Atmosphere |]      (1/760) (Just "Torr")---declareDerivedUnit "Calorie"     [t| Joule           |] 4.184          (Just "cal")-declareDerivedUnit "FoodCalorie" [t| Kilo :@ Calorie |] 1              (Just "Cal")-declareDerivedUnit "Therm"       [t| Mega :@ Joule   |] 105.4804       (Just "thm")-declareDerivedUnit "Btu"         [t| Joule           |] 1055.05585262  (Just "btu")--declareDerivedUnit "Horsepower" [t| Watt   |] 746       (Just "hp")--declareDerivedUnit "Rankine"    [t| Kelvin |] (5/9)  (Just "°R")--declareDerivedUnit "PoundForce" [t| Newton |] 4.4482216152605 (Just "lbf")--declareDerivedUnit "Slug"       [t| PoundForce :* (Second :^ Two) :/ Foot |]-                                1 (Just "slug")--declareDerivedUnit "Oersted"    [t| Ampere :/ Meter |]-                                (1000 / (4 * piR)) (Just "Oe")---- | Standard lengths: 'Foot', 'Inch', 'Yard', and 'Mile'-lengths :: [Name]-lengths = [ ''Foot, ''Inch, ''Yard, ''Mile ]--
− units-defs/Data/Units/US/Survey.hs
@@ -1,53 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.Survey--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines survey measures as used in the USA.--- Note that a survey foot is ever so slightly different from a standard--- foot.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.Survey where--import Data.Metrology-import Data.Metrology.TH-import Data.Units.SI--import Language.Haskell.TH--declareDerivedUnit "Foot"    [t| Meter    |] (1200/3937) (Just "ft")-declareDerivedUnit "Link"    [t| Foot     |] 0.66        (Just "li")-declareDerivedUnit "Rod"     [t| Link     |] 25          (Just "rd")-declareDerivedUnit "Chain"   [t| Rod      |] 4           (Just "ch")-declareDerivedUnit "Furlong" [t| Chain    |] 10          (Just "fur")-declareDerivedUnit "Mile"    [t| Furlong  |] 8           (Just "mi")-declareDerivedUnit "League"  [t| Mile     |] 3           (Just "lea")---- | Includes all the lengths above.-surveyLengths :: [Name]-surveyLengths = [ ''Foot, ''Link, ''Rod, ''Chain, ''Furlong-                , ''Mile, ''League ]--declareDerivedUnit "Acre"     [t| Foot :^ Two |] 43560 (Just "acre")-declareDerivedUnit "Section"  [t| Acre |]        640   (Just "section")-declareDerivedUnit "Township" [t| Section |]     36    (Just "twp")---- | Includes all the areas above.-surveyAreas :: [Name]-surveyAreas = [ ''Acre, ''Section, ''Township ]
− units-defs/Data/Units/US/Troy.hs
@@ -1,43 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module      :  Data.Units.US.Troy--- Copyright   :  (C) 2013 Richard Eisenberg--- License     :  BSD-style (see LICENSE)--- Maintainer  :  Richard Eisenberg (eir@cis.upenn.edu)--- Stability   :  experimental--- Portability :  non-portable------ This module defines troy measures of mass. The troy--- system is most often used when measuring precious metals.------ Included are all units mentioned here:--- http://en.wikipedia.org/wiki/United_States_customary_units--- Where possible, conversion rates have been independently verified--- at a US government website. However, Wikipedia's base is /much/--- better organized than any government resource immediately available.--- The US government references used are as follows:--- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf--- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf--------------------------------------------------------------------------------module Data.Units.US.Troy (-  module Data.Units.US.Troy,--  -- | The avoirdupois grain is the same as the troy grain-  Grain(..)-  ) where--import Data.Metrology.TH-import Data.Units.US.Avoirdupois ( Grain(..) )--import Language.Haskell.TH--declareDerivedUnit "Pennyweight" [t| Grain       |] 24 (Just "dwt")-declareDerivedUnit "Ounce"       [t| Pennyweight |] 20 (Just "ozt")-declareDerivedUnit "Pound"       [t| Ounce       |] 12 (Just "lbt")---- | Includes 'Grain', 'Pennyweight', 'Ounce', and 'Pound'-troyMassMeasures :: [Name]-troyMassMeasures = [ ''Grain, ''Pennyweight, ''Ounce, ''Pound ]
units.cabal view
@@ -1,29 +1,19 @@ name:           units-version:        2.3+version:        2.4.1.5 cabal-version:  >= 1.10 synopsis:       A domain-specific type system for dimensional analysis homepage:       https://github.com/goldfirere/units category:       Math-author:         Richard Eisenberg <eir@cis.upenn.edu>-maintainer:     Richard Eisenberg <eir@cis.upenn.edu>, Takayuki Muranushi <muranushi@gmail.com>+author:         Richard Eisenberg <rae@richarde.dev>, Takayuki Muranushi <muranushi@gmail.com>+maintainer:     Richard Eisenberg <rae@richarde.dev> bug-reports:    https://github.com/goldfirere/units/issues stability:      experimental extra-source-files: README.md                   , CHANGES.md-                  , Tests/*.hs-                  , Tests/README.md-                  , Tests/Compile/*.hs-                  , Tests/Compile/UnitParser/*.hs-                  , units-defs/Data/Constants/*.hs-                  , units-defs/Data/Dimensions/*.hs-                  , units-defs/Data/Metrology/*.hs-                  , units-defs/Data/Metrology/SI/*.hs-                  , units-defs/Data/Units/*.hs-                  , units-defs/Data/Units/SI/*.hs-                  , units-defs/Data/Units/US/*.hs license:        BSD3 license-file:   LICENSE build-type:     Simple+Tested-With: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.1, GHC == 8.6.3, GHC == 8.8.1, GHC == 8.10.4, GHC == 9.0.1, GHC == 9.2.1 description:      The units package provides a mechanism for compile-time@@ -37,16 +27,20 @@     value is converted into that unit.      If you are looking for specific systems of units (such as SI),-    please see the `units-defs` package.+    please see the @units-defs@ package. +    Tests for this package are in a companion package @units-test@,+    available from this package's source repository.+     The Haddock documentation is insufficient for using the units     package. Please see the README file, available from the package     home page. + source-repository this   type:     git   location: https://github.com/goldfirere/units.git-  tag:      v2.3+  tag:      v2.4.1.5  library   ghc-options: -Wall@@ -54,16 +48,37 @@   if impl(ghc >= 7.10)     ghc-options: -fno-warn-unticked-promoted-constructors -  build-depends: base >= 4.7 && < 5-               , th-desugar >= 1.5.4-               , singletons >= 0.9 && < 2-               , vector-space >= 0.8-               , template-haskell-               , mtl >= 1.1-               , multimap >= 1.2-               , syb >= 0.3-               , containers >= 0.4-               , units-parser >= 0.1 && < 1.0+  if impl(ghc >= 9.0)+    build-depends: base >= 4.7 && < 5+                 , th-desugar >= 1.5.4+                 , singletons == 3.*+                 , singletons-th == 3.*+                 , singletons-base == 3.*+                 , vector-space >= 0.8+                 , linear >= 1.16.2+                 , template-haskell+                 , mtl >= 1.1+                 , multimap >= 1.2+                 , syb >= 0.3+                 , containers >= 0.4+                 , units-parser >= 0.1 && < 1.0+                 , lens >= 4 && < 6+                 , deepseq >= 1.1.0.0 && < 1.5+  else+    build-depends: base >= 4.7 && < 5+                 , th-desugar >= 1.5.4+                 , singletons >= 0.9 && < 3+                       -- keep it < 3 to avoid the need for singletons-th and -base+                 , vector-space >= 0.8+                 , linear >= 1.16.2+                 , template-haskell+                 , mtl >= 1.1+                 , multimap >= 1.2+                 , syb >= 0.3+                 , containers >= 0.4+                 , units-parser >= 0.1 && < 1.0+                 , lens >= 4 && < 6+                 , deepseq >= 1.1.0.0 && < 1.5   exposed-modules:     Data.Metrology,     Data.Metrology.Internal,@@ -72,6 +87,7 @@     Data.Metrology.Z,     Data.Metrology.Set,     Data.Metrology.Vector,+    Data.Metrology.Linear,     Data.Metrology.Parser,     Data.Metrology.Poly,     Data.Metrology.TH,@@ -90,31 +106,3 @@   other-extensions: TemplateHaskell   default-language: Haskell2010 -test-suite main-  type:             exitcode-stdio-1.0-  main-is:          Tests/Main.hs-  default-language: Haskell2010-  build-depends:    units-                  , base >= 4.7 && < 5-                  , th-desugar >= 1.5.4-                  , singletons >= 0.9 && < 2-                  , vector-space >= 0.8-                  , tasty >= 0.8-                  , tasty-hunit >= 0.8-                  , HUnit-approx >= 1.0-                  , template-haskell-                  , mtl >= 1.1-                  , multimap >= 1.2-                  , syb >= 0.3-                  , containers >= 0.4-                  , units-parser >= 0.1 && < 1.0-  hs-source-dirs:   units-defs, .--    -- optimize compile time, not runtime!-  ghc-options:        -O0 -Wall -main-is Tests.Main-  if impl(ghc >= 7.10)-    ghc-options: -fno-warn-unticked-promoted-constructors--    -- GHC 7.10 requires this in more places, and I don't feel like ferreting out exactly-    -- where.-  default-extensions: FlexibleContexts