units-defs 1.1 → 2.0
raw patch · 27 files changed
+1052/−631 lines, 27 filesdep ~units
Dependency ranges changed: units
Files
- CHANGES.md +7/−1
- Data/Constants/Math.hs +19/−0
- Data/Constants/Mechanics.hs +26/−0
- Data/Dimensions/SI.hs +60/−0
- Data/Metrology/SI.hs +1/−3
- Data/Metrology/SI/Dims.hs +0/−72
- Data/Metrology/SI/Mono.hs +11/−8
- Data/Metrology/SI/MonoTypes.hs +3/−2
- Data/Metrology/SI/Parser.hs +0/−29
- Data/Metrology/SI/Poly.hs +7/−7
- Data/Metrology/SI/PolyTypes.hs +1/−1
- Data/Metrology/SI/Prefixes.hs +0/−227
- Data/Metrology/SI/Units.hs +0/−266
- Data/Units/CGS.hs +56/−0
- Data/Units/PreciousMetals.hs +28/−0
- Data/Units/SI.hs +106/−0
- Data/Units/SI/Parser.hs +29/−0
- Data/Units/SI/Prefixes.hs +227/−0
- Data/Units/US.hs +62/−0
- Data/Units/US/Apothecaries.hs +46/−0
- Data/Units/US/Avoirdupois.hs +50/−0
- Data/Units/US/DryVolume.hs +47/−0
- Data/Units/US/Liquid.hs +60/−0
- Data/Units/US/Misc.hs +85/−0
- Data/Units/US/Survey.hs +53/−0
- Data/Units/US/Troy.hs +43/−0
- units-defs.cabal +25/−15
CHANGES.md view
@@ -1,5 +1,11 @@+Version 2.0+-----------++* Full re-organization of modules.+* Addition of US customary units, CGS units, and a few other gubbins.+ Version 1.1--------------+----------- * Added `si` parser. * Moved `DefaultUnitOfDim` instances from `SI.MonoTypes` to `SI.Mono`. This allows
+ Data/Constants/Math.hs view
@@ -0,0 +1,19 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Constants.Math+-- Copyright : (C) 2014 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- Approximates mathematical constants as 'Rational's+-----------------------------------------------------------------------------++module Data.Constants.Math where++piR :: Rational+piR = 3.1415926535897932384626433832795028841971693993751058209749445923078164++eR :: Rational+eR = 2.71828182845904523536028747135266249775724709369995957496696762772407663
+ Data/Constants/Mechanics.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE TypeOperators, ConstraintKinds, TemplateHaskell #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Constants.Mechanics+-- Copyright : (C) 2014 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This file defines dimensioned physical constants, useful in mechanics.+--+-- The names used are a short description of the constant followed by its+-- usual symbol, separated by an underscore. For non-Latin symbols, the+-- Latin-lettered transliteration of the symbol name is used.+-----------------------------------------------------------------------------++module Data.Constants.Mechanics where++import Data.Metrology.Poly+import Data.Metrology.SI.Poly+import Data.Metrology.TH++-- | Acceleration at Earth's surface due to gravity.+declareConstant "gravity_g" 9.80665 [t| Meter :/ Second :^ Two |]
+ Data/Dimensions/SI.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE TypeOperators, TemplateHaskell #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Dimensions.SI+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines SI dimensions. The names of SI dimensions conform to+-- <http://www.bipm.org/utils/common/documents/jcgm/JCGM_200_2012.pdf>.+-----------------------------------------------------------------------------++module Data.Dimensions.SI where++import Data.Metrology.Poly+import Data.Metrology.TH++declareDimension "Length"+declareDimension "Mass"+declareDimension "Time"+declareDimension "Current"+declareDimension "Temperature"+declareDimension "AmountOfSubstance"+declareDimension "LuminousIntensity"++type Area = Length :^ Two+type Volume = Length :^ Three+type Velocity = Length :/ Time+type Acceleration = Velocity :/ Time+type Wavenumber = Length :^ MOne+type Density = Mass :/ Volume+type SurfaceDensity = Mass :/ Area+type SpecificVolume = Volume :/ Mass+type CurrentDensity = Current :/ Area+type MagneticStrength = Current :/ Length+type Concentration = AmountOfSubstance :/ Volume+type Luminance = LuminousIntensity :/ Area++type Frequency = Time :^ MOne+type Force = Mass :* Acceleration+type Pressure = Force :/ Area+type Energy = Force :* Length+type Power = Energy :/ Time+type Charge = Current :* Time+type ElectricPotential = Power :/ Current+type Capacitance = Charge :/ ElectricPotential+type Resistance = ElectricPotential :/ Current+type Conductance = Current :/ ElectricPotential+type MagneticFlux = ElectricPotential :* Time+type MagneticFluxDensity = MagneticFlux :/ Area+type Inductance = MagneticFlux :/ Current+type LuminousFlux = LuminousIntensity+type Illuminance = LuminousIntensity :/ Area+type Kerma = Area :/ (Time :^ Two)+type CatalyticActivity = AmountOfSubstance :/ Time++type Momentum = Mass :* Velocity
Data/Metrology/SI.hs view
@@ -17,9 +17,7 @@ ----------------------------------------------------------------------------- module Data.Metrology.SI (- module Data.Metrology.SI.Mono+ module Data.Metrology.SI.Mono, ) where import Data.Metrology.SI.Mono--
− Data/Metrology/SI/Dims.hs
@@ -1,72 +0,0 @@-{-# LANGUAGE TypeOperators #-}---------------------------------------------------------------------------------- |--- Module : Data.Metrology.SI.Dims--- Copyright : (C) 2013 Richard Eisenberg--- License : BSD-style (see LICENSE)--- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)--- Stability : experimental--- Portability : non-portable------ This module defines SI dimensions. The names of SI dimensions conform to--- <http://www.bipm.org/utils/common/documents/jcgm/JCGM_200_2012.pdf>.--------------------------------------------------------------------------------module Data.Metrology.SI.Dims where--import Data.Metrology--data Length = Length-instance Dimension Length--data Mass = Mass-instance Dimension Mass--data Time = Time-instance Dimension Time--data Current = Current-instance Dimension Current--data Temperature = Temperature-instance Dimension Temperature--data AmountOfSubstance = AmountOfSubstance-instance Dimension AmountOfSubstance--data LuminousIntensity = LuminousIntensity-instance Dimension 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
Data/Metrology/SI/Mono.hs view
@@ -11,22 +11,25 @@ -- -- This module exports definitions for the SI system, with the intent -- of using these definitions in a monomorphic manner -- that is,--- with the DefaultLCSU.+-- 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.Metrology.SI.Units,- module Data.Metrology.SI.Prefixes,- module Data.Metrology.SI.Parser+ module Data.Units.SI,+ module Data.Units.SI.Prefixes,+ module Data.Units.SI.Parser ) where import Data.Metrology.SI.MonoTypes-import Data.Metrology.SI.Units-import Data.Metrology.SI.Prefixes-import qualified Data.Metrology.SI.Dims as D+import Data.Units.SI+import Data.Units.SI.Prefixes+import qualified Data.Dimensions.SI as D import Data.Metrology-import Data.Metrology.SI.Parser+import Data.Units.SI.Parser type instance DefaultUnitOfDim D.Length = Meter type instance DefaultUnitOfDim D.Mass = Kilo :@ Gram
Data/Metrology/SI/MonoTypes.hs view
@@ -10,13 +10,14 @@ -- Portability : non-portable -- -- This module defines type synonyms for SI units, using a Double as the--- internal representation.+-- 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.Metrology.SI.Dims as D+import qualified Data.Dimensions.SI as D type Length = MkQu_D D.Length type Mass = MkQu_D D.Mass
− Data/Metrology/SI/Parser.hs
@@ -1,29 +0,0 @@-{-# LANGUAGE TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module : Data.Metrology.SI.Parser--- Copyright : (C) 2013 Richard Eisenberg--- License : BSD-style (see LICENSE)--- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)--- Stability : experimental--- Portability : non-portable------ Defines a quasi-quoting parser for unit expressions. Writing, say,--- @[si| m/s^2 |]@ produces @(Meter :/ (Second :^ sTwo))@. A larger--- example is------ > ke :: Energy--- > ke = 5 % [si| N km |] -- 5 Newton-kilometers------ See `Data.Metrology.Parser` for more information about the syntax--- of these unit expressions.--------------------------------------------------------------------------------module Data.Metrology.SI.Parser where--import Data.Metrology.Parser-import Data.Metrology.SI.Prefixes-import Data.Metrology.SI.Units--makeQuasiQuoter "si" siPrefixes siUnits
Data/Metrology/SI/Poly.hs view
@@ -17,17 +17,17 @@ module Data.Metrology.SI.Poly ( SI, module Data.Metrology.SI.PolyTypes,- module Data.Metrology.SI.Prefixes,- module Data.Metrology.SI.Units,- module Data.Metrology.SI.Parser+ module Data.Units.SI.Prefixes,+ module Data.Units.SI,+ module Data.Units.SI.Parser ) where import Data.Metrology.SI.PolyTypes-import Data.Metrology.SI.Prefixes-import Data.Metrology.SI.Units-import qualified Data.Metrology.SI.Dims as D+import Data.Units.SI.Prefixes+import Data.Units.SI+import qualified Data.Dimensions.SI as D import Data.Metrology-import Data.Metrology.SI.Parser+import Data.Units.SI.Parser type SI = MkLCSU '[ (D.Length, Meter) , (D.Mass, Kilo :@ Gram)
Data/Metrology/SI/PolyTypes.hs view
@@ -16,7 +16,7 @@ module Data.Metrology.SI.PolyTypes where import Data.Metrology-import qualified Data.Metrology.SI.Dims as D+import qualified Data.Dimensions.SI as D type Length = MkQu_DLN D.Length type Mass = MkQu_DLN D.Mass
− Data/Metrology/SI/Prefixes.hs
@@ -1,227 +0,0 @@-{-# LANGUAGE TypeOperators, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module : Data.Metrology.SI.Prefixes--- Copyright : (C) 2013 Richard Eisenberg--- License : BSD-style (see LICENSE)--- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)--- Stability : experimental--- Portability : non-portable------ Defines prefixes from the SI standard at <http://www.bipm.org/en/si/>--------------------------------------------------------------------------------module Data.Metrology.SI.Prefixes where--import Language.Haskell.TH ( Name )-import Data.Metrology---- | 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- ]
− Data/Metrology/SI/Units.hs
@@ -1,266 +0,0 @@-{-# LANGUAGE TypeFamilies, TypeOperators, PatternSynonyms, TemplateHaskell #-}---------------------------------------------------------------------------------- |--- Module : Data.Metrology.SI.Units--- Copyright : (C) 2013 Richard Eisenberg--- License : BSD-style (see LICENSE)--- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)--- Stability : experimental--- Portability : non-portable------ This module exports unit definitions according to the SI system of units.--- The definitions were taken from here: <http://www.bipm.org/en/si/>.------ Some additional units were added base 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 definition 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.Metrology.SI.Units where--import Data.Metrology-import Data.Metrology.SI.Dims-import Data.Metrology.SI.Prefixes ( Kilo, Centi )--import Language.Haskell.TH ( Name )--data Meter = Meter-instance Unit Meter where- type BaseUnit Meter = Canonical- type DimOfUnit Meter = Length-instance Show Meter where- show _ = "m"--type Metre = Meter-pattern Metre = Meter--data Gram = Gram-instance Unit Gram where- type BaseUnit Gram = Canonical- type DimOfUnit Gram = Mass-instance Show Gram where- show _ = "g"--data Second = Second-instance Unit Second where- type BaseUnit Second = Canonical- type DimOfUnit Second = Time-instance Show Second where- show _ = "s"---- | Derived SI unit-data Minute = Minute-instance Unit Minute where- type BaseUnit Minute = Second- conversionRatio _ = 60-instance Show Minute where- show _ = "min"---- | Derived SI unit-data Hour = Hour-instance Unit Hour where- type BaseUnit Hour = Minute- conversionRatio _ = 60-instance Show Hour where- show _ = "h"--data Day = Day-instance Unit Day where- type BaseUnit Day = Hour- conversionRatio _ = 24-instance Show Day where- show _ = "d"--data Ampere = Ampere-instance Unit Ampere where- type BaseUnit Ampere = Canonical- type DimOfUnit Ampere = Current-instance Show Ampere where- show _ = "A"--data Kelvin = Kelvin-instance Unit Kelvin where- type BaseUnit Kelvin = Canonical- type DimOfUnit Kelvin = Temperature-instance Show Kelvin where- show _ = "K"--data Mole = Mole-instance Unit Mole where- type BaseUnit Mole = Canonical- type DimOfUnit Mole = AmountOfSubstance-instance Show Mole where- show _ = "mol"--data Candela = Candela-instance Unit Candela where- type BaseUnit Candela = Canonical- type DimOfUnit Candela = LuminousIntensity-instance Show Candela where- show _ = "cd"--data Hertz = Hertz-instance Unit Hertz where- type BaseUnit Hertz = Number :/ Second-instance Show Hertz where- show _ = "Hz"---- | This is not in the SI standard, but is used widely.-data Liter = Liter-instance Unit Liter where- type BaseUnit Liter = (Centi :@ Meter) :^ Three- conversionRatio _ = 1000-instance Show Liter where- show _ = "l"--type Litre = Liter-pattern Litre = Liter--data Newton = Newton-instance Unit Newton where- type BaseUnit Newton = Gram :* Meter :/ (Second :^ Two)- conversionRatio _ = 1000-instance Show Newton where- show _ = "N"--data Pascal = Pascal-instance Unit Pascal where- type BaseUnit Pascal = Newton :/ (Meter :^ Two)-instance Show Pascal where- show _ = "Pa"--data Joule = Joule-instance Unit Joule where- type BaseUnit Joule = Newton :* Meter-instance Show Joule where- show _ = "J"--data Watt = Watt-instance Unit Watt where- type BaseUnit Watt = Joule :/ Second-instance Show Watt where- show _ = "W"--data Coulomb = Coulomb-instance Unit Coulomb where- type BaseUnit Coulomb = Ampere :* Second-instance Show Coulomb where- show _ = "C"--data Volt = Volt-instance Unit Volt where- type BaseUnit Volt = Watt :/ Ampere-instance Show Volt where- show _ = "V"--data Farad = Farad-instance Unit Farad where- type BaseUnit Farad = Coulomb :/ Volt-instance Show Farad where- show _ = "F"--data Ohm = Ohm-instance Unit Ohm where- type BaseUnit Ohm = Volt :/ Ampere-instance Show Ohm where- show _ = "Ω"--data Siemens = Siemens-instance Unit Siemens where- type BaseUnit Siemens = Ampere :/ Volt-instance Show Siemens where- show _ = "S"--data Weber = Weber-instance Unit Weber where- type BaseUnit Weber = Volt :* Second-instance Show Weber where- show _ = "Wb"--data Tesla = Tesla-instance Unit Tesla where- type BaseUnit Tesla = Weber :/ (Meter :^ Two)-instance Show Tesla where- show _ = "T"--data Henry = Henry-instance Unit Henry where- type BaseUnit Henry = Weber :/ Ampere-instance Show Henry where- show _ = "H"--data Lumen = Lumen-instance Unit Lumen where- type BaseUnit Lumen = Candela-instance Show Lumen where- show _ = "lm"--data Lux = Lux-instance Unit Lux where- type BaseUnit Lux = Lumen :/ (Meter :^ Two)-instance Show Lux where- show _ = "lx"--data Becquerel = Becquerel-instance Unit Becquerel where- type BaseUnit Becquerel = Number :/ Second-instance Show Becquerel where- show _ = "Bq"--data Gray = Gray-instance Unit Gray where- type BaseUnit Gray = (Meter :^ Two) :/ (Second :^ Two)-instance Show Gray where- show _ = "Gy"--data Sievert = Sievert-instance Unit Sievert where- type BaseUnit Sievert = (Meter :^ Two) :/ (Second :^ Two)-instance Show Sievert where- show _ = "Sv"--data Katal = Katal-instance Unit Katal where- type BaseUnit Katal = Mole :/ Second-instance Show Katal where- show _ = "kat"---- | Derived SI unit-data Hectare = Hectare-instance Unit Hectare where- type BaseUnit Hectare = Meter :^ Two- conversionRatio _ = 10000-instance Show Hectare where- show _ = "ha"---- | Derived SI unit-data Ton = Ton-instance Unit Ton where- type BaseUnit Ton = Kilo :@ Gram- conversionRatio _ = 1000-instance Show Ton where- show _ = "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, ''Day, ''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- ]-
+ Data/Units/CGS.hs view
@@ -0,0 +1,56 @@+{-# LANGUAGE PatternSynonyms, TemplateHaskell, TypeOperators,+ TypeFamilies #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.CGS+-- Copyright : (C) 2014 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines units used in the centimeter/gram/second system+-- of measurement.+--+-- Included are all mechanical units mentioned here:+-- http://en.wikipedia.org/wiki/Centimetre%E2%80%93gram%E2%80%93second_system_of_units+--+-- Some electromagnetic units are not included, because these do not have+-- reliable conversions to/from the SI units, on which the @units-defs@+-- edifice is based.+-----------------------------------------------------------------------------++module Data.Units.CGS (+ Centi(..), centi, Meter(..), pattern Metre, Gram(..), Second(..),+ module Data.Units.CGS+ ) where++import Data.Units.SI+import Data.Units.SI.Prefixes+import Data.Metrology.Poly+import Data.Metrology.TH++type Centimeter = Centi :@ Meter+pattern Centimeter = Centi :@ Meter++type Centimetre = Centimeter+pattern Centimetre = Centimeter++declareDerivedUnit "Gal"+ [t| Centimeter :/ Second :^ Two |] 1 (Just "Gal")+declareDerivedUnit "Dyne"+ [t| Gram :* Centimeter :/ Second :^ Two |] 1 (Just "dyn")+declareDerivedUnit "Erg"+ [t| Gram :* Centimeter :^ Two :/ Second :^ Two |] 1 (Just "erg")+declareDerivedUnit "Barye"+ [t| Gram :/ (Centimeter :* Second :^ Two) |] 1 (Just "Ba")+declareDerivedUnit "Poise"+ [t| Gram :/ (Centimeter :* Second) |] 1 (Just "P")+declareDerivedUnit "Stokes"+ [t| Centimeter :^ Two :/ Second |] 1 (Just "St")+declareDerivedUnit "Kayser"+ [t| Centimeter :^ MOne |] 1 Nothing++declareDerivedUnit "Maxwell" [t| Nano :@ Weber |] 10 (Just "Mx")+declareDerivedUnit "Gauss" [t| Milli :@ Tesla |] 0.1 (Just "G")
+ Data/Units/PreciousMetals.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Metrology.Units.PreciousMetals+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- Units used in the measure of precious metals.+-----------------------------------------------------------------------------++module Data.Units.PreciousMetals where++import Data.Metrology+import Data.Metrology.TH+import Data.Units.SI+import Data.Units.SI.Prefixes++import qualified Data.Units.US.Avoirdupois as Avdp+import qualified Data.Units.US.Troy as Troy++declareDerivedUnit "Carat" [t| Milli :@ Gram |] 200 (Just "carat")+declareDerivedUnit "Point" [t| Carat |] 0.01 (Just "point")+declareDerivedUnit "AssayTon" [t| (Milli :@ Gram) :* (Avdp.Ton :/ Troy.Ounce) |]+ 1 (Just "AT")
+ Data/Units/SI.hs view
@@ -0,0 +1,106 @@+{-# LANGUAGE TypeFamilies, TypeOperators, PatternSynonyms, TemplateHaskell #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.SI+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module exports unit definitions according to the SI system of units.+-- The definitions were taken from here: <http://www.bipm.org/en/si/>.+--+-- Some additional units were added based on+-- <http://www.bipm.org/en/si/si_brochure/chapter4/table6.html this link>:+-- "Non-SI units accepted for use with the SI,+-- and units based on fundamental constants".+--+-- There is one deviation from the definitions at that site: To work better+-- with prefixes, the unit of mass is 'Gram'.+--+-- This module exports both American spellings and British spellings of+-- units, using pattern synonyms to get the British spellings of data+-- constructors.+-----------------------------------------------------------------------------++module Data.Units.SI where++import Data.Metrology.Poly+import Data.Metrology.TH+import Data.Dimensions.SI+import Data.Units.SI.Prefixes ( Kilo, Centi )++import Language.Haskell.TH ( Name )++declareCanonicalUnit "Meter" [t| Length |] (Just "m")++type Metre = Meter+pattern Metre = Meter++declareCanonicalUnit "Gram" [t| Mass |] (Just "g")++type Gramme = Gram+pattern Gramme = Gram++declareCanonicalUnit "Second" [t| Time |] (Just "s")++-- | Derived SI unit+declareDerivedUnit "Minute" [t| Second |] 60 (Just "min")++-- | Derived SI unit+declareDerivedUnit "Hour" [t| Minute |] 60 (Just "h")++declareCanonicalUnit "Ampere" [t| Current |] (Just "A")+declareCanonicalUnit "Kelvin" [t| Temperature |] (Just "K")+declareCanonicalUnit "Mole" [t| AmountOfSubstance |] (Just "mol")+declareCanonicalUnit "Candela" [t| LuminousIntensity |] (Just "cd")++declareDerivedUnit "Hertz" [t| Number :/ Second |] 1 (Just "Hz")++-- | This is not in the SI standard, but is used widely.+declareDerivedUnit "Liter" [t| (Centi :@ Meter) :^ Three |] 1000 (Just "L")++type Litre = Liter+pattern Litre = Liter++declareDerivedUnit "Newton" [t| Gram :* Meter :/ (Second :^ Two) |] 1000 (Just "N")+declareDerivedUnit "Pascal" [t| Newton :/ (Meter :^ Two) |] 1 (Just "Pa")+declareDerivedUnit "Joule" [t| Newton :* Meter |] 1 (Just "J")+declareDerivedUnit "Watt" [t| Joule :/ Second |] 1 (Just "W")+declareDerivedUnit "Coulomb" [t| Ampere :* Second |] 1 (Just "C")+declareDerivedUnit "Volt" [t| Watt :/ Ampere |] 1 (Just "V")+declareDerivedUnit "Farad" [t| Coulomb :/ Volt |] 1 (Just "F")+declareDerivedUnit "Ohm" [t| Volt :/ Ampere |] 1 (Just "Ω")+declareDerivedUnit "Siemens" [t| Ampere :/ Volt |] 1 (Just "S")+declareDerivedUnit "Weber" [t| Volt :* Second |] 1 (Just "Wb")+declareDerivedUnit "Tesla" [t| Weber :/ (Meter :^ Two) |] 1 (Just "T")+declareDerivedUnit "Henry" [t| Weber :/ Ampere |] 1 (Just "H")+declareDerivedUnit "Lumen" [t| Candela |] 1 (Just "lm")+declareDerivedUnit "Lux" [t| Lumen :/ (Meter :^ Two) |] 1 (Just "lx")+declareDerivedUnit "Becquerel" [t| Number :/ Second |] 1 (Just "Bq")+declareDerivedUnit "Gray" [t| (Meter :^ Two) :/ (Second :^ Two) |] 1 (Just "Gy")+declareDerivedUnit "Sievert" [t| (Meter :^ Two) :/ (Second :^ Two) |] 1 (Just "Sv")+declareDerivedUnit "Katal" [t| Mole :/ Second |] 1 (Just "kat")++-- | Derived SI unit+declareDerivedUnit "Hectare" [t| Meter :^ Two |] 10000 (Just "ha")++-- | Derived SI unit+declareDerivedUnit "Ton" [t| Kilo :@ Gram |] 1000 (Just "t")++type Tonne = Ton+pattern Tonne = Ton++-- | A list of the names of all unit types. Useful with+-- 'Data.Metrology.Parser.makeQuasiQuoter'.+siUnits :: [Name]+siUnits =+ [ ''Meter, ''Gram, ''Second, ''Minute, ''Hour, ''Ampere+ , ''Kelvin, ''Mole, ''Candela, ''Hertz, ''Liter, ''Newton, ''Pascal+ , ''Joule, ''Watt, ''Coulomb, ''Volt, ''Farad, ''Ohm, ''Siemens+ , ''Weber, ''Tesla, ''Henry, ''Lumen, ''Lux, ''Becquerel, ''Gray+ , ''Sievert, ''Katal, ''Hectare, ''Ton+ ]+
+ Data/Units/SI/Parser.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE TemplateHaskell #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.SI.Parser+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- Defines a quasi-quoting parser for unit expressions. Writing, say,+-- @[si| m/s^2 |]@ produces @(Meter :/ (Second :^ sTwo))@. A larger+-- example is+--+-- > ke :: Energy+-- > ke = 5 % [si| N km |] -- 5 Newton-kilometers+--+-- See `Data.Metrology.Parser` for more information about the syntax+-- of these unit expressions.+-----------------------------------------------------------------------------++module Data.Units.SI.Parser ( si ) where++import Data.Metrology.Parser+import Data.Units.SI.Prefixes+import Data.Units.SI++makeQuasiQuoter "si" siPrefixes siUnits
+ Data/Units/SI/Prefixes.hs view
@@ -0,0 +1,227 @@+{-# LANGUAGE TypeOperators, TemplateHaskell #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.SI.Prefixes+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- Defines prefixes from the SI standard at <http://www.bipm.org/en/si/>+-----------------------------------------------------------------------------++module Data.Units.SI.Prefixes where++import Language.Haskell.TH ( Name )+import Data.Metrology.Poly++-- | 10^1+data Deca = Deca+instance UnitPrefix Deca where+ multiplier _ = 1e1+instance Show Deca where+ show _ = "da"++deca :: unit -> Deca :@ unit+deca = (Deca :@)++-- | 10^2+data Hecto = Hecto+instance UnitPrefix Hecto where+ multiplier _ = 1e2+instance Show Hecto where+ show _ = "h"++hecto :: unit -> Hecto :@ unit+hecto = (Hecto :@)++-- | 10^3+data Kilo = Kilo+instance UnitPrefix Kilo where+ multiplier _ = 1e3+instance Show Kilo where+ show _ = "k"++kilo :: unit -> Kilo :@ unit+kilo = (Kilo :@)++-- | 10^6+data Mega = Mega+instance UnitPrefix Mega where+ multiplier _ = 1e6+instance Show Mega where+ show _ = "M"++mega :: unit -> Mega :@ unit+mega = (Mega :@)++-- | 10^9+data Giga = Giga+instance UnitPrefix Giga where+ multiplier _ = 1e9+instance Show Giga where+ show _ = "G"++giga :: unit -> Giga :@ unit+giga = (Giga :@)++-- | 10^12+data Tera = Tera+instance UnitPrefix Tera where+ multiplier _ = 1e12+instance Show Tera where+ show _ = "T"++tera :: unit -> Tera :@ unit+tera = (Tera :@)++-- | 10^15+data Peta = Peta+instance UnitPrefix Peta where+ multiplier _ = 1e15+instance Show Peta where+ show _ = "P"++peta :: unit -> Peta :@ unit+peta = (Peta :@)++-- | 10^18+data Exa = Exa+instance UnitPrefix Exa where+ multiplier _ = 1e18+instance Show Exa where+ show _ = "E"++exa :: unit -> Exa :@ unit+exa = (Exa :@)++-- | 10^21+data Zetta = Zetta+instance UnitPrefix Zetta where+ multiplier _ = 1e21+instance Show Zetta where+ show _ = "Z"++zetta :: unit -> Zetta :@ unit+zetta = (Zetta :@)++-- | 10^24+data Yotta = Yotta+instance UnitPrefix Yotta where+ multiplier _ = 1e24+instance Show Yotta where+ show _ = "Y"++yotta :: unit -> Yotta :@ unit+yotta = (Yotta :@)++-- | 10^-1+data Deci = Deci+instance UnitPrefix Deci where+ multiplier _ = 1e-1+instance Show Deci where+ show _ = "d"++deci :: unit -> Deci :@ unit+deci = (Deci :@)++-- | 10^-2+data Centi = Centi+instance UnitPrefix Centi where+ multiplier _ = 1e-2+instance Show Centi where+ show _ = "c"++centi :: unit -> Centi :@ unit+centi = (Centi :@)++-- | 10^-3+data Milli = Milli+instance UnitPrefix Milli where+ multiplier _ = 1e-3+instance Show Milli where+ show _ = "m"++milli :: unit -> Milli :@ unit+milli = (Milli :@)++-- | 10^-6+data Micro = Micro+instance UnitPrefix Micro where+ multiplier _ = 1e-6+instance Show Micro where+ show _ = "μ"++micro :: unit -> Micro :@ unit+micro = (Micro :@)++-- | 10^-9+data Nano = Nano+instance UnitPrefix Nano where+ multiplier _ = 1e-9+instance Show Nano where+ show _ = "n"++nano :: unit -> Nano :@ unit+nano = (Nano :@)++-- | 10^-12+data Pico = Pico+instance UnitPrefix Pico where+ multiplier _ = 1e-12+instance Show Pico where+ show _ = "p"++pico :: unit -> Pico :@ unit+pico = (Pico :@)++-- | 10^-15+data Femto = Femto+instance UnitPrefix Femto where+ multiplier _ = 1e-15+instance Show Femto where+ show _ = "f"++femto :: unit -> Femto :@ unit+femto = (Femto :@)++-- | 10^-18+data Atto = Atto+instance UnitPrefix Atto where+ multiplier _ = 1e-18+instance Show Atto where+ show _ = "a"++atto :: unit -> Atto :@ unit+atto = (Atto :@)++-- | 10^-21+data Zepto = Zepto+instance UnitPrefix Zepto where+ multiplier _ = 1e-21+instance Show Zepto where+ show _ = "z"++zepto :: unit -> Zepto :@ unit+zepto = (Zepto :@)++-- | 10^-24+data Yocto = Yocto+instance UnitPrefix Yocto where+ multiplier _ = 1e-24+instance Show Yocto where+ show _ = "y"++yocto :: unit -> Yocto :@ unit+yocto = (Yocto :@)++-- | A list of the names of all prefix types. Useful with+-- 'Data.Metrology.Parser.makeQuasiQuoter'.+siPrefixes :: [Name]+siPrefixes =+ [ ''Deca, ''Hecto, ''Kilo, ''Mega, ''Giga, ''Tera, ''Peta, ''Exa+ , ''Zetta, ''Yotta, ''Deci, ''Centi, ''Milli, ''Micro, ''Nano+ , ''Pico, ''Femto, ''Atto, ''Zepto, ''Yocto+ ]
+ Data/Units/US.hs view
@@ -0,0 +1,62 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines the American customary system of units. Because+-- there are some names that are conflicted, even within this system,+-- there are several modules underneath here, defining sub-parts of+-- the US system. This module gathers together a subjective set of+-- units users will commonly wish to use. It also exports type instances+-- 'DefaultUnitOfDim' that use the /SI/ internal representations. This+-- choice is made for inter-compatibility with SI computations. If you+-- want the foot-pound-second system, use the 'FPS'.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US (+ -- * Lengths+ Angstrom(..), Mil(..), Point(..), Pica(..),+ Inch(..), Foot(..), Yard(..), Mile(..), NauticalMile(..),++ -- * Velocity+ Knot(..),+ + -- * Area+ Survey.Acre(..),++ -- * Volume+ -- | These are all /liquid/ measures. Solid measures are /different/.+ Liq.Teaspoon(..), Liq.Tablespoon(..), Liq.FluidOunce(..),+ Liq.Cup(..), Liq.Pint(..), Liq.Quart(..), Liq.Gallon(..),++ -- * Mass+ -- | These are all in the avoirdupois system+ Avdp.Ounce(..), Avdp.Pound(..), Avdp.Ton(..),++ -- * Pressure+ Atmosphere(..), Bar(..),++ -- * Energy+ FoodCalorie(..), Therm(..), Btu(..),++ -- * Power+ Horsepower(..)+ ) where++import Data.Units.US.Misc+import qualified Data.Units.US.Survey as Survey+import qualified Data.Units.US.Liquid as Liq+import qualified Data.Units.US.Avoirdupois as Avdp
+ Data/Units/US/Apothecaries.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.Apothecaries+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines apothecaries' measures of mass. These measures+-- are rarely used.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.Apothecaries (+ module Data.Units.US.Apothecaries,++ -- | The apothecaries' grain is the same as the avoirdupois grain.+ Grain(..),++ -- | The apothecaries' ounce and pound are the troy ounce and pound.+ Ounce(..), Pound(..)+ ) where++import Data.Metrology.TH+import Data.Units.US.Avoirdupois ( Grain(..) )+import Data.Units.US.Troy ( Ounce(..), Pound(..) )++import Language.Haskell.TH++declareDerivedUnit "Scruple" [t| Grain |] 20 (Just "sap")+declareDerivedUnit "Dram" [t| Grain |] 60 (Just "drap")++-- | Includes 'Grain', 'Scruple', 'Dram', 'Ounce', and 'Pound'.+apothecariesMassMeasures :: [Name]+apothecariesMassMeasures = [ ''Grain, ''Scruple, ''Dram, ''Ounce, ''Pound ]
+ Data/Units/US/Avoirdupois.hs view
@@ -0,0 +1,50 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.Avoirdupois+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines avoirdupois measures of mass. The avoirdupois+-- system is the one most commonly used in the US.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.Avoirdupois where++import Data.Metrology.TH+import Data.Units.SI ( Gram )++import Language.Haskell.TH++declareDerivedUnit "Pound" [t| Gram |] 453.59237 (Just "lb")++declareDerivedUnit "Grain" [t| Pound |] (1/7000) (Just "gr")+declareDerivedUnit "Dram" [t| Grain |] (27 + 11/32) (Just "dr")+declareDerivedUnit "Ounce" [t| Pound |] (1/16) (Just "oz")+declareDerivedUnit "Hundredweight" [t| Pound |] 100 (Just "cwt")+declareDerivedUnit "LongHundredweight" [t| Pound |] 112 (Just "longcwt")+declareDerivedUnit "Ton" [t| Pound |] 2000 (Just "ton")+declareDerivedUnit "LongTon" [t| Pound |] 2240 (Just "longton")++-- | Includes 'Ounce', 'Pound', 'Ton'+commonMassMeasures :: [Name]+commonMassMeasures = [ ''Ounce, ''Pound, ''Ton]++-- | Includes 'Grain', 'Dram', 'Hundredweight', 'LongHundredweight',+-- and 'LongTon'+otherMassMeasures :: [Name]+otherMassMeasures = [ ''Grain, ''Dram, ''Hundredweight, ''LongHundredweight+ , ''LongTon ]
+ Data/Units/US/DryVolume.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.DryVolume+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines dry volume measures as used in the USA.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.DryVolume where++import Data.Metrology+import Data.Metrology.TH+import Data.Units.US.Misc++import Language.Haskell.TH++declareDerivedUnit "Gallon" [t| Inch :^ Three |] 268.8025 (Just "gal")+declareDerivedUnit "Quart" [t| Gallon |] (1/4) (Just "qt")+declareDerivedUnit "Pint" [t| Quart |] (1/2) (Just "pt")+declareDerivedUnit "Peck" [t| Gallon |] 2 (Just "pk")+declareDerivedUnit "Bushel" [t| Peck |] 4 (Just "bu")+declareDerivedUnit "Barrel" [t| Inch :^ Three |] 7056 (Just "bbl")+declareDerivedUnit "Cord" [t| Foot :^ Three |] 128 (Just "cd")+declareDerivedUnit "BoardFoot" [t| Foot :^ Three |] (1/12) (Just "FBM")+declareDerivedUnit "RegisterTon" [t| Foot :^ Three |] 100 (Just "RT")++declareDerivedUnit "CranberryBarrel" [t| Inch :^ Three |] 5826 (Just "bbl")++-- | Includes all measures in this file, except 'CranberryBarrel'.+dryVolumeMeasures :: [Name]+dryVolumeMeasures = [ ''Pint, ''Quart, ''Gallon, ''Peck, ''Bushel+ , ''Barrel, ''Cord, ''BoardFoot, ''RegisterTon ]
+ Data/Units/US/Liquid.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.Liquid+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines liquid volume measures as used in the USA.+-- Note that liquid volumes in the USA differ both from solid volumes+-- in the USA and from liquid volumes in the UK.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.Liquid where++import Data.Metrology+import Data.Metrology.TH+import Data.Units.US.Misc++import Language.Haskell.TH++declareDerivedUnit "Gallon" [t| Inch :^ Three |] 231 (Just "gal")++declareDerivedUnit "FluidOunce" [t| Gallon |] (1/128) (Just "floz")+declareDerivedUnit "Gill" [t| FluidOunce |] 4 (Just "gi")+declareDerivedUnit "Cup" [t| FluidOunce |] 8 (Just "cp")+declareDerivedUnit "Pint" [t| FluidOunce |] 16 (Just "pt")+declareDerivedUnit "Quart" [t| Gallon |] (1/4) (Just "qt")++declareDerivedUnit "Teaspoon" [t| FluidOunce |] (1/6) (Just "tsp")+declareDerivedUnit "Tablespoon" [t| Teaspoon |] 3 (Just "Tbsp")+declareDerivedUnit "Shot" [t| Tablespoon |] 3 (Just "jig")+declareDerivedUnit "Minim" [t| Teaspoon |] (1/80) (Just "min")+declareDerivedUnit "Dram" [t| Minim |] 60 (Just "fldr")++declareDerivedUnit "Hogshead" [t| Gallon |] 63 (Just "hogshead")+declareDerivedUnit "Barrel" [t| Hogshead |] (1/2) (Just "bbl")+declareDerivedUnit "OilBarrel" [t| Gallon |] 42 (Just "bbl")++-- | As shown on Wikipedia: http://en.wikipedia.org/wiki/United_States_customary_units+commonLiquidMeasures :: [Name]+commonLiquidMeasures = [ ''Teaspoon, ''Tablespoon, ''FluidOunce, ''Cup, ''Pint+ , ''Quart, ''Gallon ]++-- | Includes the rest of the measures in this file.+otherLiquidMeasures :: [Name]+otherLiquidMeasures = [ ''Minim, ''Dram, ''Shot, ''Gill, ''Barrel+ , ''OilBarrel, ''Hogshead ]
+ Data/Units/US/Misc.hs view
@@ -0,0 +1,85 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.Misc+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines American customary units that don't fit into+-- other categories.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.Misc (+ module Data.Units.US.Misc,+ Maxwell(..)+ ) where++import Data.Metrology+import Data.Metrology.TH++import Data.Units.SI+import Data.Units.SI.Prefixes+import Data.Units.CGS+import Data.Constants.Math++import Language.Haskell.TH++declareDerivedUnit "Foot" [t| Meter |] 0.3048 (Just "ft")+declareDerivedUnit "Inch" [t| Foot |] (1/12) (Just "in")+declareDerivedUnit "Yard" [t| Foot |] 3 (Just "yd")+declareDerivedUnit "Mile" [t| Foot |] 5280 (Just "mi")+declareDerivedUnit "Angstrom" [t| Nano :@ Meter |] 0.1 (Just "Å")+declareDerivedUnit "Hand" [t| Inch |] 4 (Just "hand")+declareDerivedUnit "Mil" [t| Inch |] 0.001 (Just "mil")++declareDerivedUnit "Point" [t| Inch |] 0.013837 (Just "p")+declareDerivedUnit "Pica" [t| Point |] 12 (Just "P")++declareDerivedUnit "Fathom" [t| Yard |] 2 (Just "ftm")+declareDerivedUnit "Cable" [t| Fathom |] 120 (Just "cb")+declareDerivedUnit "NauticalMile" [t| Kilo :@ Meter |] 1.852 (Just "NM")++declareDerivedUnit "Knot" [t| NauticalMile :/ Hour |] 1 (Just "kn")++declareDerivedUnit "Atmosphere" [t| Kilo :@ Pascal |] 101.325 (Just "atm")+declareDerivedUnit "Bar" [t| Kilo :@ Pascal |] 100 (Just "bar")+declareDerivedUnit "MillimeterOfMercury"+ [t| Pascal |] 133.322387415 (Just "mmHg")+declareDerivedUnit "Torr" [t| Atmosphere |] (1/760) (Just "Torr")+++declareDerivedUnit "Calorie" [t| Joule |] 4.184 (Just "cal")+declareDerivedUnit "FoodCalorie" [t| Kilo :@ Calorie |] 1 (Just "Cal")+declareDerivedUnit "Therm" [t| Mega :@ Joule |] 105.4804 (Just "thm")+declareDerivedUnit "Btu" [t| Joule |] 1055.05585262 (Just "btu")++declareDerivedUnit "Horsepower" [t| Watt |] 746 (Just "hp")++declareDerivedUnit "Rankine" [t| Kelvin |] (5/9) (Just "°R")++declareDerivedUnit "PoundForce" [t| Newton |] 4.4482216152605 (Just "lbf")++declareDerivedUnit "Slug" [t| PoundForce :* (Second :^ Two) :/ Foot |]+ 1 (Just "slug")++declareDerivedUnit "Oersted" [t| Ampere :/ Meter |]+ (1000 / (4 * piR)) (Just "Oe")++-- | Standard lengths: 'Foot', 'Inch', 'Yard', and 'Mile'+lengths :: [Name]+lengths = [ ''Foot, ''Inch, ''Yard, ''Mile ]++
+ Data/Units/US/Survey.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.Survey+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines survey measures as used in the USA.+-- Note that a survey foot is ever so slightly different from a standard+-- foot.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.Survey where++import Data.Metrology+import Data.Metrology.TH+import Data.Units.SI++import Language.Haskell.TH++declareDerivedUnit "Foot" [t| Meter |] (1200/3937) (Just "ft")+declareDerivedUnit "Link" [t| Foot |] 0.66 (Just "li")+declareDerivedUnit "Rod" [t| Link |] 25 (Just "rd")+declareDerivedUnit "Chain" [t| Rod |] 4 (Just "ch")+declareDerivedUnit "Furlong" [t| Chain |] 10 (Just "fur")+declareDerivedUnit "Mile" [t| Furlong |] 8 (Just "mi")+declareDerivedUnit "League" [t| Mile |] 3 (Just "lea")++-- | Includes all the lengths above.+surveyLengths :: [Name]+surveyLengths = [ ''Foot, ''Link, ''Rod, ''Chain, ''Furlong+ , ''Mile, ''League ]++declareDerivedUnit "Acre" [t| Foot :^ Two |] 43560 (Just "acre")+declareDerivedUnit "Section" [t| Acre |] 640 (Just "section")+declareDerivedUnit "Township" [t| Section |] 36 (Just "twp")++-- | Includes all the areas above.+surveyAreas :: [Name]+surveyAreas = [ ''Acre, ''Section, ''Township ]
+ Data/Units/US/Troy.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Units.US.Troy+-- Copyright : (C) 2013 Richard Eisenberg+-- License : BSD-style (see LICENSE)+-- Maintainer : Richard Eisenberg (eir@cis.upenn.edu)+-- Stability : experimental+-- Portability : non-portable+--+-- This module defines troy measures of mass. The troy+-- system is most often used when measuring precious metals.+--+-- Included are all units mentioned here:+-- http://en.wikipedia.org/wiki/United_States_customary_units+-- Where possible, conversion rates have been independently verified+-- at a US government website. However, Wikipedia's base is /much/+-- better organized than any government resource immediately available.+-- The US government references used are as follows:+-- http://nist.gov/pml/wmd/metric/upload/SP1038.pdf+-- http://nist.gov/pml/wmd/pubs/upload/appc-14-hb44-final.pdf+-----------------------------------------------------------------------------++module Data.Units.US.Troy (+ module Data.Units.US.Troy,++ -- | The avoirdupois grain is the same as the troy grain+ Grain(..)+ ) where++import Data.Metrology.TH+import Data.Units.US.Avoirdupois ( Grain(..) )++import Language.Haskell.TH++declareDerivedUnit "Pennyweight" [t| Grain |] 24 (Just "dwt")+declareDerivedUnit "Ounce" [t| Pennyweight |] 20 (Just "ozt")+declareDerivedUnit "Pound" [t| Ounce |] 12 (Just "lbt")++-- | Includes 'Grain', 'Pennyweight', 'Ounce', and 'Pound'+troyMassMeasures :: [Name]+troyMassMeasures = [ ''Grain, ''Pennyweight, ''Ounce, ''Pound ]
units-defs.cabal view
@@ -1,5 +1,5 @@ name: units-defs-version: 1.1+version: 2.0 cabal-version: >= 1.10 synopsis: Definitions for use with the units package homepage: http://github.com/goldfirere/units-defs@@ -22,26 +22,36 @@ source-repository this type: git location: https://github.com/goldfirere/units-defs.git- tag: v1.1+ tag: v2.0 library build-depends: base >= 4.7 && < 5,- units >= 2.1 && < 3,+ units >= 2.2 && < 3, template-haskell exposed-modules:- Data.Metrology.SI,- Data.Metrology.SI.Mono,- Data.Metrology.SI.Poly,- Data.Metrology.SI.Prefixes,- Data.Metrology.SI.MonoTypes, - Data.Metrology.SI.Units,- Data.Metrology.SI.Dims,- Data.Metrology.SI.PolyTypes,- Data.Metrology.SI.Parser--- Data.Metrology.Imperial.Types--- Data.Metrology.Imperial.Units+ Data.Constants.Mechanics+ Data.Constants.Math+ Data.Dimensions.SI+ Data.Metrology.SI+ Data.Metrology.SI.Mono+ Data.Metrology.SI.Poly+ Data.Metrology.SI.MonoTypes+ Data.Metrology.SI.PolyTypes+ Data.Units.SI+ Data.Units.SI.Prefixes+ Data.Units.SI.Parser+ Data.Units.CGS+ Data.Units.US+ Data.Units.US.Apothecaries+ Data.Units.US.Avoirdupois+ Data.Units.US.DryVolume+ Data.Units.US.Liquid+ Data.Units.US.Misc+ Data.Units.US.Survey+ Data.Units.US.Troy+ Data.Units.PreciousMetals default-language: Haskell2010- default-extensions: TemplateHaskell+ other-extensions: TemplateHaskell ghc-options: -Wall