Copyright | (C) 2013 Richard Eisenberg |
---|---|
License | (C) 2013 Richard Eisenberg |
Maintainer | Richard Eisenberg (eir@cis.upenn.edu) |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
The units package is a framework for strongly-typed dimensional analysis. This haddock documentation is generally not enough to be able to use this package effectively. Please see the readme at http://www.cis.upenn.edu/~eir/packages/units/README.html.
Some of the types below refer to declarations that are not exported and not documented here. This is because Haddock does not allow finely-tuned abstraction in documentation. (In particular, right-hand sides of type synonym declarations are always included.) If a symbol is not exported, you do not need to know anything about it to use this package.
Though it doesn't appear here, Scalar
is an instance of Num
, and
generally has all the numeric instances that Double
has.
- (.+) :: (d1 @~ d2, Num n) => Dim n d1 -> Dim n d2 -> Dim n d1
- (.-) :: (d1 @~ d2, Num n) => Dim n d1 -> Dim n d2 -> Dim n d1
- (.*) :: Num n => Dim n a -> Dim n b -> Dim n (Normalize (a @+ b))
- (./) :: Fractional n => Dim n a -> Dim n b -> Dim n (Normalize (a @- b))
- (.^) :: Fractional n => Dim n a -> Sing z -> Dim n (a @* z)
- (*.) :: Num n => n -> Dim n a -> Dim n a
- (.<) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> Bool
- (.>) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> Bool
- (.<=) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> Bool
- (.>=) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> Bool
- dimEq :: (d0 @~ d1, d0 @~ d2, Num n, Ord n) => Dim n d0 -> Dim n d1 -> Dim n d2 -> Bool
- dimNeq :: (d0 @~ d1, d0 @~ d2, Num n, Ord n) => Dim n d0 -> Dim n d1 -> Dim n d2 -> Bool
- nthRoot :: ((Zero < z) ~ True, Floating n) => Sing z -> Dim n a -> Dim n (a @/ z)
- dimSqrt :: Floating n => Dim n a -> Dim n (a @/ Two)
- dimCubeRoot :: Floating n => Dim n a -> Dim n (a @/ Three)
- unity :: Num n => Dim n `[]`
- zero :: Num n => Dim n dimspec
- dim :: d @~ e => Dim n d -> Dim n e
- dimIn :: Unit unit => MkDim (CanonicalUnit unit) -> unit -> Double
- (#) :: Unit unit => MkDim (CanonicalUnit unit) -> unit -> Double
- dimOf :: Unit unit => Double -> unit -> MkDim (CanonicalUnit unit)
- (%) :: Unit unit => Double -> unit -> MkDim (CanonicalUnit unit)
- data u1 :* u2 = u1 :* u2
- data u1 :/ u2 = u1 :/ u2
- data unit :^ power = unit :^ (Sing power)
- data prefix :@ unit = prefix :@ unit
- class UnitPrefix prefix where
- multiplier :: prefix -> Double
- type family d1 (%*) d2 :: *
- type family d1 (%/) d2 :: *
- type family d (%^) z :: *
- class Unit unit where
- type BaseUnit unit :: *
- conversionRatio :: unit -> Double
- type MkDim unit = Dim Double (DimSpecsOf unit)
- type MkGenDim n unit = Dim n (DimSpecsOf unit)
- data Canonical
- data Number = Number
- type Scalar = MkDim Number
- scalar :: n -> Dim n `[]`
- data Z
- type family Succ z :: Z
- type family Pred z :: Z
- type family a (#+) b :: Z
- type family a (#-) b :: Z
- type family a (#*) b :: Z
- type family a (#/) b :: Z
- type family NegZ z :: Z
- type One = S Zero
- type Two = S One
- type Three = S Two
- type Four = S Three
- type Five = S Four
- type MOne = P Zero
- type MTwo = P MOne
- type MThree = P MTwo
- type MFour = P MThree
- type MFive = P MFour
- pZero :: Sing Z Zero
- pOne :: Sing Z (S Zero)
- pTwo :: Sing Z (S (S Zero))
- pThree :: Sing Z (S (S (S Zero)))
- pFour :: Sing Z (S (S (S (S Zero))))
- pFive :: Sing Z (S (S (S (S (S Zero)))))
- pMOne :: Sing Z (P Zero)
- pMTwo :: Sing Z (P (P Zero))
- pMThree :: Sing Z (P (P (P Zero)))
- pMFour :: Sing Z (P (P (P (P Zero))))
- pMFive :: Sing Z (P (P (P (P (P Zero)))))
- pSucc :: Sing z -> Sing (Succ z)
- pPred :: Sing z -> Sing (Pred z)
Term-level combinators
(.+) :: (d1 @~ d2, Num n) => Dim n d1 -> Dim n d2 -> Dim n d1Source
Add two compatible dimensioned quantities
(.-) :: (d1 @~ d2, Num n) => Dim n d1 -> Dim n d2 -> Dim n d1Source
Subtract two compatible dimensioned quantities
(.*) :: Num n => Dim n a -> Dim n b -> Dim n (Normalize (a @+ b))Source
Multiply two dimensioned quantities
(./) :: Fractional n => Dim n a -> Dim n b -> Dim n (Normalize (a @- b))Source
Divide two dimensioned quantities
(.^) :: Fractional n => Dim n a -> Sing z -> Dim n (a @* z)Source
Raise a dimensioned quantity to a power known at compile time
(.<) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> BoolSource
Check if one dimensioned quantity is less than a compatible one
(.>) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> BoolSource
Check if one dimensioned quantity is greater than a compatible one
(.<=) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> BoolSource
Check if one dimensioned quantity is less than or equal to a compatible one
(.>=) :: (d1 @~ d2, Ord n) => Dim n d1 -> Dim n d2 -> BoolSource
Check if one dimensioned quantity is greater than or equal to a compatible one
:: (d0 @~ d1, d0 @~ d2, Num n, Ord n) | |
=> Dim n d0 | If the difference between the next two arguments are less than this amount, they are considered equal |
-> Dim n d1 | |
-> Dim n d2 | |
-> Bool |
Compare two compatible dimensioned quantities for equality
:: (d0 @~ d1, d0 @~ d2, Num n, Ord n) | |
=> Dim n d0 | If the difference between the next two arguments are less than this amount, they are considered equal |
-> Dim n d1 | |
-> Dim n d2 | |
-> Bool |
Compare two compatible dimensioned quantities for inequality
nthRoot :: ((Zero < z) ~ True, Floating n) => Sing z -> Dim n a -> Dim n (a @/ z)Source
Take the n'th root of a dimensioned quantity, where n is known at compile time
dimSqrt :: Floating n => Dim n a -> Dim n (a @/ Two)Source
Take the square root of a dimensioned quantity
dimCubeRoot :: Floating n => Dim n a -> Dim n (a @/ Three)Source
Take the cube root of a dimensioned quantity
zero :: Num n => Dim n dimspecSource
The number 0, polymorphic in its dimension. Use of this will often require a type annotation.
dimIn :: Unit unit => MkDim (CanonicalUnit unit) -> unit -> DoubleSource
Extracts a Double
from a dimensioned quantity, expressed in
the given unit. For example:
inMeters :: Length -> Double inMeters x = dimIn x Meter
dimOf :: Unit unit => Double -> unit -> MkDim (CanonicalUnit unit)Source
Creates a dimensioned quantity in the given unit. For example:
height :: Length height = dimOf 2.0 Meter
Type-level unit combinators
Multiply two units to get another unit.
For example: type MetersSquared = Meter :* Meter
u1 :* u2 |
Divide two units to get another unit
u1 :/ u2 |
Raise a unit to a power, known at compile time
Multiply a conversion ratio by some constant. Used for defining prefixes.
prefix :@ unit |
class UnitPrefix prefix whereSource
A class for user-defined prefixes
multiplier :: prefix -> DoubleSource
This should return the desired multiplier for the prefix being defined. This function must not inspect its argument.
Type-level dimensioned-quantity combinators
type family d1 (%*) d2 :: *Source
Multiply two dimension types to produce a new one. For example:
type Velocity = Length %/ Time
Creating new units
Class of units. Make an instance of this class to define a new unit.
The base unit of this unit: what this unit is defined in terms of.
For units that are not defined in terms of anything else, the base unit
should be Canonical
.
conversionRatio :: unit -> DoubleSource
The conversion ratio from the base unit to this unit. If left out, a conversion ratio of 1 is assumed.
For example:
instance Unit Foot where type BaseUnit Foot = Meter conversionRatio _ = 0.3048
Implementations should never examine their argument!
Unit Number | |
Unit Katal | |
Unit Sievert | |
Unit Gray | |
Unit Becquerel | |
Unit Lux | |
Unit Lumen | |
Unit Henry | |
Unit Tesla | |
Unit Weber | |
Unit Siemens | |
Unit Ohm | |
Unit Farad | |
Unit Volt | |
Unit Coulomb | |
Unit Watt | |
Unit Joule | |
Unit Pascal | |
Unit Newton | |
Unit Hertz | |
Unit Candela | |
Unit Mole | |
Unit Kelvin | |
Unit Ampere | |
Unit Second | |
Unit Gram | |
Unit Meter | |
(~ Bool (CheckCanonical unit) False, Unit unit, UnitPrefix prefix) => Unit (:@ prefix unit) | |
(Unit unit, SingI Z power) => Unit (:^ unit power) | |
(Unit u1, Unit u2) => Unit (:/ u1 u2) | |
(Unit u1, Unit u2) => Unit (:* u1 u2) |
type MkDim unit = Dim Double (DimSpecsOf unit)Source
Make a dimensioned quantity type capable of storing a value of a given
unit. This uses a Double
for storage of the value. For example:
type Length = MkDim Meter
type MkGenDim n unit = Dim n (DimSpecsOf unit)Source
Make a dimensioned quantity with a custom numerical type.
Dummy type use just to label canonical units. It does not have a
Unit
instance.
Scalars, the only built-in unit
type Scalar = MkDim NumberSource
The type of unitless dimensioned quantities
This is an instance of Num
, though Haddock doesn't show it.
Type-level integers
The datatype for type-level integers.
Synonyms for small numbers
Term-level singletons
This is the singleton value representing Zero
at the term level and
at the type level, simultaneously. Used for raising units to powers.