units 2.4.1.3 → 2.4.1.4
raw patch · 58 files changed
+98/−2913 lines, 58 filesdep +singletons-basedep +singletons-thdep −HUnit-approxdep −tastydep −tasty-hunitdep ~lensdep ~singletons
Dependencies added: singletons-base, singletons-th
Dependencies removed: HUnit-approx, tasty, tasty-hunit, units
Dependency ranges changed: lens, singletons
Files
- Data/Metrology/Dimensions.hs +5/−1
- Data/Metrology/Factor.hs +14/−1
- Data/Metrology/LCSU.hs +6/−1
- Data/Metrology/Qu.hs +4/−0
- Data/Metrology/Quantity.hs +5/−1
- Data/Metrology/Show.hs +4/−0
- Data/Metrology/TH.hs +8/−2
- Data/Metrology/Units.hs +4/−0
- Data/Metrology/Validity.hs +5/−1
- Data/Metrology/Z.hs +5/−1
- Tests/Compile/CGS.hs +0/−15
- Tests/Compile/EvalType.hs +0/−22
- Tests/Compile/Lcsu.hs +0/−37
- Tests/Compile/MetrologySynonyms.hs +0/−153
- Tests/Compile/NoVector.hs +0/−10
- Tests/Compile/Physics.hs +0/−76
- Tests/Compile/Quantity.hs +0/−35
- Tests/Compile/Readme.hs +0/−98
- Tests/Compile/Simulator.hs +0/−126
- Tests/Compile/T23.hs +0/−12
- Tests/Compile/TH.hs +0/−25
- Tests/Compile/UnitParser.hs +0/−46
- Tests/Compile/UnitParser/Quoters.hs +0/−18
- Tests/Compile/Units.hs +0/−40
- Tests/Imperial.hs +0/−27
- Tests/LennardJones.hs +0/−213
- Tests/Linearity.hs +0/−30
- Tests/Main.hs +0/−57
- Tests/OffSystemAdd.hs +0/−62
- Tests/OffSystemCSU.hs +0/−36
- Tests/Parser.hs +0/−129
- Tests/PhysicalConstants.hs +0/−114
- Tests/README.md +0/−19
- Tests/Show.hs +0/−24
- Tests/Travel.hs +0/−104
- Tests/Vector.hs +0/−44
- units-defs/Data/Constants/Math.hs +0/−19
- units-defs/Data/Constants/Mechanics.hs +0/−26
- units-defs/Data/Dimensions/SI.hs +0/−60
- units-defs/Data/Metrology/SI.hs +0/−23
- units-defs/Data/Metrology/SI/Mono.hs +0/−40
- units-defs/Data/Metrology/SI/MonoTypes.hs +0/−59
- units-defs/Data/Metrology/SI/Poly.hs +0/−39
- units-defs/Data/Metrology/SI/PolyTypes.hs +0/−58
- units-defs/Data/Units/CGS.hs +0/−56
- units-defs/Data/Units/PreciousMetals.hs +0/−28
- units-defs/Data/Units/SI.hs +0/−105
- units-defs/Data/Units/SI/Parser.hs +0/−29
- units-defs/Data/Units/SI/Prefixes.hs +0/−227
- units-defs/Data/Units/US.hs +0/−62
- units-defs/Data/Units/US/Apothecaries.hs +0/−46
- units-defs/Data/Units/US/Avoirdupois.hs +0/−50
- units-defs/Data/Units/US/DryVolume.hs +0/−47
- units-defs/Data/Units/US/Liquid.hs +0/−60
- units-defs/Data/Units/US/Misc.hs +0/−83
- units-defs/Data/Units/US/Survey.hs +0/−53
- units-defs/Data/Units/US/Troy.hs +0/−43
- units.cabal +38/−120
Data/Metrology/Dimensions.hs view
@@ -10,7 +10,11 @@ {-# 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
Data/Metrology/Factor.hs view
@@ -9,8 +9,17 @@ 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)@@ -18,7 +27,11 @@ 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.
Data/Metrology/LCSU.hs view
@@ -10,7 +10,12 @@ 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/Qu.hs view
@@ -19,6 +19,10 @@ {-# 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
Data/Metrology/Quantity.hs view
@@ -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/Show.hs view
@@ -6,6 +6,10 @@ {-# LANGUAGE OverlappingInstances #-} #endif +#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ {-# OPTIONS_GHC -fno-warn-orphans #-} -----------------------------------------------------------------------------
Data/Metrology/TH.hs view
@@ -187,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)@@ -199,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
Data/Metrology/Units.hs view
@@ -16,6 +16,10 @@ {-# LANGUAGE UndecidableSuperClasses #-} #endif +#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif+ module Data.Metrology.Units where import Data.Metrology.Z
Data/Metrology/Validity.hs view
@@ -8,7 +8,11 @@ -} {-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, PolyKinds,- UndecidableInstances #-}+ UndecidableInstances, CPP #-}++#if __GLASGOW_HASKELL__ >= 900+{-# OPTIONS_GHC -Wno-star-is-type #-}+#endif module Data.Metrology.Validity where
Data/Metrology/Z.hs view
@@ -10,7 +10,8 @@ {-# LANGUAGE TypeFamilies, DataKinds, TypeOperators, UndecidableInstances, GADTs, PolyKinds, TemplateHaskell, ScopedTypeVariables,- EmptyCase, CPP, TypeSynonymInstances, FlexibleInstances #-}+ EmptyCase, CPP, TypeSynonymInstances, FlexibleInstances,+ InstanceSigs #-} #if __GLASGOW_HASKELL__ >= 800 {-# LANGUAGE TypeApplications #-} #endif@@ -75,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.
− 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" (assertBool "NaN" (isNaN $ ljForce (4 % Å) # Newton))- , testCase "NaNPoly" (assertBool "NaNPoly" (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" (assertBool "ansNaN" $ isNaN $ (ans :: Force SI Float) # Newton)- , testCase "ansCU" ((ans :: Force CU Float) # Newton @?~ val)- , testCase "optNaN" (assertBool "optNaN" $ isNaN $ (ljForcePOpt aParaAr bParaAr (4%Å) :: Force SI Float) # Newton)- , testCase "optCU" ((ljForcePOpt aParaAr bParaAr (4%Å) :: Force CU Float) # Newton @?~ val)- , testCase "precompNaN" (assertBool "precompNaN" $ isNaN $ (ljForcePOpt aParaAr' bParaAr' (4%Å) :: Force SI Float) # Newton)- , testCase "precompNaN2" (assertBool "precompNaN2" $ isNaN $ (ljForcePOpt aParaAr' bParaAr' (4%Å) :: Force CU Float) # Newton)- , testCase "precompPolyNaN" (assertBool "precompPolyNaN" $ 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,57 +0,0 @@-{- Test/Main.hs-- The units Package- Copyright (c) 2014 Richard Eisenberg- rae@cs.brynmawr.edu-- This is the main testing file for the units package.--}--{-# LANGUAGE ImplicitParams #-}--module 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.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.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,114 +0,0 @@-{-# LANGUAGE ConstraintKinds, DataKinds, FlexibleContexts, TypeFamilies,- TypeOperators, ImplicitParams, CPP #-}-{-# OPTIONS_GHC -fno-warn-missing-signatures #-}--#if __GLASGOW_HASKELL__ >= 711-{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}-#endif--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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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,105 +0,0 @@-{-# LANGUAGE TypeFamilies, TypeOperators, PatternSynonyms, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module : Data.Units.SI--- Copyright : (C) 2013 Richard Eisenberg--- License : BSD-style (see LICENSE)--- Maintainer : Richard Eisenberg (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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,83 +0,0 @@-{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}---------------------------------------------------------------------------------- |--- Module : Data.Units.US.Misc--- Copyright : (C) 2013 Richard Eisenberg--- License : BSD-style (see LICENSE)--- Maintainer : Richard Eisenberg (rae@cs.brynmawr.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 (rae@cs.brynmawr.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 (rae@cs.brynmawr.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,5 +1,5 @@ name: units-version: 2.4.1.3+version: 2.4.1.4 cabal-version: >= 1.10 synopsis: A domain-specific type system for dimensional analysis homepage: https://github.com/goldfirere/units@@ -10,21 +10,10 @@ 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.2, GHC == 7.10.3, GHC == 8.0.1, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.1, GHC == 8.6.3, GHC == 8.8.1+Tested-With: GHC == 7.8.4, GHC == 7.10.2, GHC == 7.10.3, GHC == 8.0.1, 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 description: The units package provides a mechanism for compile-time@@ -38,12 +27,16 @@ 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@@ -55,19 +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 && < 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 && < 5- , deepseq >= 1.1.0.0 && < 1.5+ 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,@@ -94,97 +105,4 @@ -- cabal now recommends that TH be explicitly listed in cabal files 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 && < 3- , vector-space >= 0.8- , linear >= 1.16.2- , 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- , lens >= 4 && < 5- , deepseq >= 1.1.0.0 && < 1.5- hs-source-dirs: units-defs, .-- -- optimize compile time, not runtime!- ghc-options: -O0 -Wall- if impl(ghc >= 7.10)- ghc-options: -fno-warn-unticked-promoted-constructors- if impl(ghc >= 8.0)- ghc-options: -Wno-missing-signatures -Wno-redundant-constraints -Wno-name-shadowing -Wno-missing-pattern-synonym-signatures-- -- GHC 7.10 requires this in more places, and I don't feel like ferreting out exactly- -- where.- default-extensions: FlexibleContexts-- other-modules:- Data.Constants.Math- Data.Dimensions.SI- Data.Metrology- Data.Metrology.Combinators- Data.Metrology.Dimensions- Data.Metrology.Factor- Data.Metrology.Internal- Data.Metrology.LCSU- Data.Metrology.Parser- Data.Metrology.Poly- Data.Metrology.Qu- Data.Metrology.Quantity- Data.Metrology.SI- Data.Metrology.SI.Mono- Data.Metrology.SI.MonoTypes- Data.Metrology.SI.Poly- Data.Metrology.SI.PolyTypes- Data.Metrology.Set- Data.Metrology.Show- Data.Metrology.TH- Data.Metrology.Units- Data.Metrology.Unsafe- Data.Metrology.Validity- Data.Metrology.Vector- Data.Metrology.Z- Data.Units.CGS- Data.Units.SI- Data.Units.SI.Parser- Data.Units.SI.Prefixes- Data.Units.US- Data.Units.US.Avoirdupois- Data.Units.US.Liquid- Data.Units.US.Misc- Data.Units.US.Survey- Tests.Compile.CGS- Tests.Compile.EvalType- Tests.Compile.Lcsu- Tests.Compile.MetrologySynonyms- Tests.Compile.NoVector- Tests.Compile.Physics- Tests.Compile.Quantity- Tests.Compile.Readme- Tests.Compile.Simulator- Tests.Compile.T23- Tests.Compile.TH- Tests.Compile.UnitParser- Tests.Compile.UnitParser.Quoters- Tests.Compile.Units- Tests.Imperial- Tests.LennardJones- Tests.Linearity- Tests.OffSystemAdd- Tests.OffSystemCSU- Tests.PhysicalConstants- Tests.Show- Tests.Travel- Tests.Vector