units-2.4.1.5: A domain-specific type system for dimensional analysis
Copyright(C) 2014 Richard Eisenberg
LicenseBSD-style (see LICENSE)
MaintainerRichard Eisenberg (rae@cs.brynmawr.edu)
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Metrology

Description

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 https://github.com/goldfirere/units/blob/master/README.md.

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, Count is an instance of Num, and generally has all the numeric instances that Double has.

This module exports definitions that lack unit-polymorphism. If you wish to write more polymorphic code, see Poly. If you wish to use the numerical hierarchy from the vector-space package, see Vector.

Synopsis

Operators working with a default LCSU

numIn :: (ValidDLU dim DefaultLCSU unit, Fractional n) => Qu dim DefaultLCSU n -> unit -> n Source #

Extracts a numerical value from a dimensioned quantity, expressed in the given unit. For example:

inMeters :: Length -> Double
inMeters x = numIn x Meter

or

inMeters x = x # Meter

(#) :: (ValidDLU dim DefaultLCSU unit, Fractional n) => Qu dim DefaultLCSU n -> unit -> n infix 5 Source #

Infix synonym for numIn

quOf :: (ValidDLU dim DefaultLCSU unit, Fractional n) => n -> unit -> Qu dim DefaultLCSU n Source #

Creates a dimensioned quantity in the given unit. For example:

height :: Length
height = quOf 2.0 Meter

or

height = 2.0 % Meter

(%) :: (ValidDLU dim DefaultLCSU unit, Fractional n) => n -> unit -> Qu dim DefaultLCSU n infixr 5 Source #

Infix synonym for quOf

type Count = MkQu_U Number Source #

The type of unitless dimensioned quantities. This is an instance of Num, though Haddock doesn't show it. This assumes a default LCSU and an internal representation of Double.

The rest of the units package interface.

Though Haddock doesn't show it, the polymorphic versions of numIn, #, quOf, %, and Count are not re-exported.

data Z Source #

The datatype for type-level integers.

Constructors

Zero 
S Z 
P Z 

Instances

Instances details
Eq Z Source # 
Instance details

Defined in Data.Metrology.Z

Methods

(==) :: Z -> Z -> Bool #

(/=) :: Z -> Z -> Bool #

SEq Z => SEq Z Source # 
Instance details

Defined in Data.Metrology.Z

Methods

(%==) :: forall (a :: Z) (b :: Z). Sing a -> Sing b -> Sing (a == b) #

(%/=) :: forall (a :: Z) (b :: Z). Sing a -> Sing b -> Sing (a /= b) #

PEq Z Source # 
Instance details

Defined in Data.Metrology.Z

Associated Types

type x == y :: Bool #

type x /= y :: Bool #

SDecide Z => SDecide Z Source # 
Instance details

Defined in Data.Metrology.Z

Methods

(%~) :: forall (a :: Z) (b :: Z). Sing a -> Sing b -> Decision (a :~: b) #

SingKind Z Source # 
Instance details

Defined in Data.Metrology.Z

Associated Types

type Demote Z = (r :: Type) #

Methods

fromSing :: forall (a :: Z). Sing a -> Demote Z #

toSing :: Demote Z -> SomeSing Z #

SDecide Z => TestCoercion SZ Source # 
Instance details

Defined in Data.Metrology.Z

Methods

testCoercion :: forall (a :: k) (b :: k). SZ a -> SZ b -> Maybe (Coercion a b) #

SDecide Z => TestEquality SZ Source # 
Instance details

Defined in Data.Metrology.Z

Methods

testEquality :: forall (a :: k) (b :: k). SZ a -> SZ b -> Maybe (a :~: b) #

SingI 'Zero Source # 
Instance details

Defined in Data.Metrology.Z

Methods

sing :: Sing 'Zero #

SingI n => SingI ('S n :: Z) Source # 
Instance details

Defined in Data.Metrology.Z

Methods

sing :: Sing ('S n) #

SingI n => SingI ('P n :: Z) Source # 
Instance details

Defined in Data.Metrology.Z

Methods

sing :: Sing ('P n) #

SuppressUnusedWarnings PSym0 Source # 
Instance details

Defined in Data.Metrology.Z

SuppressUnusedWarnings SSym0 Source # 
Instance details

Defined in Data.Metrology.Z

SingI PSym0 Source # 
Instance details

Defined in Data.Metrology.Z

Methods

sing :: Sing PSym0 #

SingI SSym0 Source # 
Instance details

Defined in Data.Metrology.Z

Methods

sing :: Sing SSym0 #

type Sing Source # 
Instance details

Defined in Data.Metrology.Z

type Sing = SZ
type Demote Z Source # 
Instance details

Defined in Data.Metrology.Z

type Demote Z = Z
type (x :: Z) /= (y :: Z) Source # 
Instance details

Defined in Data.Metrology.Z

type (x :: Z) /= (y :: Z) = Not (x == y)
type (a :: Z) == (b :: Z) Source # 
Instance details

Defined in Data.Metrology.Z

type (a :: Z) == (b :: Z)
type Apply PSym0 (a6989586621679064021 :: Z) Source # 
Instance details

Defined in Data.Metrology.Z

type Apply PSym0 (a6989586621679064021 :: Z) = PSym1 a6989586621679064021
type Apply SSym0 (a6989586621679064019 :: Z) Source # 
Instance details

Defined in Data.Metrology.Z

type Apply SSym0 (a6989586621679064019 :: Z) = SSym1 a6989586621679064019

type family Elem (a :: k) (bs :: [k]) :: Constraint where ... Source #

Is an element contained in a list?

Equations

Elem a (a ': bs) = () :: Constraint 
Elem a (b ': bs) = a `Elem` bs 

type family Subset (as :: [k]) (bs :: [k]) :: Constraint where ... Source #

Is one list a subset of the other?

Equations

Subset '[] bs = () :: Constraint 
Subset (a ': as) bs = (a `Elem` bs, as `Subset` bs) 

type family SetEqual (as :: [k]) (bs :: [k]) :: Constraint where ... Source #

Are two lists equal, when considered as sets?

Equations

SetEqual as bs = (Subset as bs, Subset bs as) 

type MTwo = P MOne Source #

type MOne = P Zero Source #

type Five = S Four Source #

type Three = S Two Source #

type Two = S One Source #

type One = S Zero Source #

type family (a :: Z) #/ (b :: Z) :: Z where ... Source #

Divide two integers

Equations

Zero #/ b = Zero 
a #/ (P b') = Negate (a #/ Negate (P b')) 
a #/ b = ZDiv b b a 

type family Negate (z :: Z) :: Z where ... Source #

Negate an integer

Equations

Negate Zero = Zero 
Negate (S z) = P (Negate z) 
Negate (P z) = S (Negate z) 

type family (a :: Z) #* (b :: Z) :: Z where ... infixl 7 Source #

Multiply two integers

Equations

Zero #* z = Zero 
(S z1) #* z2 = (z1 #* z2) #+ z2 
(P z1) #* z2 = (z1 #* z2) #- z2 

type family (a :: Z) #- (b :: Z) :: Z where ... infixl 6 Source #

Subtract two integers

Equations

z #- Zero = z 
(S z1) #- (S z2) = z1 #- z2 
Zero #- (S z2) = P (Zero #- z2) 
(P z1) #- (S z2) = P (P (z1 #- z2)) 
(S z1) #- (P z2) = S (S (z1 #- z2)) 
Zero #- (P z2) = S (Zero #- z2) 
(P z1) #- (P z2) = z1 #- z2 

type family (a :: Z) #+ (b :: Z) :: Z where ... infixl 6 Source #

Add two integers

Equations

Zero #+ z = z 
(S z1) #+ (S z2) = S (S (z1 #+ z2)) 
(S z1) #+ Zero = S z1 
(S z1) #+ (P z2) = z1 #+ z2 
(P z1) #+ (S z2) = z1 #+ z2 
(P z1) #+ Zero = P z1 
(P z1) #+ (P z2) = P (P (z1 #+ z2)) 

type family Pred (z :: Z) :: Z where ... Source #

Subtract one from an integer

Equations

Pred Zero = P Zero 
Pred (P z) = P (P z) 
Pred (S z) = z 

type family Succ (z :: Z) :: Z where ... Source #

Add one to an integer

Equations

Succ Zero = S Zero 
Succ (P z) = z 
Succ (S z) = S (S z) 

sZero :: SZ 'Zero Source #

This is the singleton value representing Zero at the term level and at the type level, simultaneously. Used for raising units to powers.

sOne :: SZ ('S 'Zero) Source #

sTwo :: SZ ('S ('S 'Zero)) Source #

sThree :: SZ ('S ('S ('S 'Zero))) Source #

sFour :: SZ ('S ('S ('S ('S 'Zero)))) Source #

sFive :: SZ ('S ('S ('S ('S ('S 'Zero))))) Source #

sMTwo :: SZ ('P ('P 'Zero)) Source #

sMThree :: SZ ('P ('P ('P 'Zero))) Source #

sMFour :: SZ ('P ('P ('P ('P 'Zero)))) Source #

sMFive :: SZ ('P ('P ('P ('P ('P 'Zero))))) Source #

sSucc :: Sing z -> Sing (Succ z) Source #

Add one to a singleton Z.

sPred :: Sing z -> Sing (Pred z) Source #

Subtract one from a singleton Z.

sNegate :: Sing z -> Sing (Negate z) Source #

Negate a singleton Z.

pZero :: SZ 'Zero Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pOne :: SZ ('S 'Zero) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pTwo :: SZ ('S ('S 'Zero)) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pThree :: SZ ('S ('S ('S 'Zero))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pFour :: SZ ('S ('S ('S ('S 'Zero)))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pFive :: SZ ('S ('S ('S ('S ('S 'Zero))))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMOne :: SZ ('P 'Zero) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMTwo :: SZ ('P ('P 'Zero)) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMThree :: SZ ('P ('P ('P 'Zero))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMFour :: SZ ('P ('P ('P ('P 'Zero)))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMFive :: SZ ('P ('P ('P ('P ('P 'Zero))))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pSucc :: forall (z :: Z). SZ z -> SZ (Succ z) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pPred :: forall (z :: Z). SZ z -> SZ (Pred z) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

type family (dims :: [Factor *]) @/ (z :: Z) :: [Factor *] where ... infixl 7 Source #

Division of the exponents in a dimension by a scalar

Equations

'[] @/ z = '[] 
(F name num ': t) @/ z = F name (num #/ z) ': (t @/ z) 

type family (base :: [Factor *]) @* (power :: Z) :: [Factor *] where ... infixl 7 Source #

Multiplication of the exponents in a dimension by a scalar

Equations

'[] @* power = '[] 
(F name num ': t) @* power = F name (num #* power) ': (t @* power) 

type family NegList (a :: [Factor *]) :: [Factor *] where ... Source #

negate a list of Factors

Equations

NegList '[] = '[] 
NegList (h ': t) = NegDim h ': NegList t 

type family NegDim (a :: Factor *) :: Factor * where ... Source #

negate a single Factor

Equations

NegDim (F n z) = F n (Negate z) 

type family (a :: [Factor *]) @- (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #

Subtract exponents in two dimensions

Equations

a @- a = '[] 
a @- b = a @@- Reorder b a 

type family (a :: [Factor *]) @@- (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #

Subtract exponents in two dimensions, assuming the lists are ordered similarly.

Equations

'[] @@- b = NegList b 
a @@- '[] = a 
(F name z1 ': t1) @@- (F name z2 ': t2) = F name (z1 #- z2) ': (t1 @@- t2) 
(h ': t) @@- b = h ': (t @@- b) 

type family (a :: [Factor *]) @+ (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #

Adds corresponding exponents in two dimension, preserving order

Equations

a @+ b = a @@+ Reorder b a 

type family (a :: [Factor *]) @@+ (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #

Adds corresponding exponents in two dimension, assuming the lists are ordered similarly.

Equations

'[] @@+ b = b 
a @@+ '[] = a 
(F name z1 ': t1) @@+ (F name z2 ': t2) = F name (z1 #+ z2) ': (t1 @@+ t2) 
(h ': t) @@+ b = h ': (t @@+ b) 

type family Normalize (d :: [Factor *]) :: [Factor *] where ... Source #

Take a [Factor *] and remove any Factors with an exponent of 0

Equations

Normalize '[] = '[] 
Normalize (F n Zero ': t) = Normalize t 
Normalize (h ': t) = h ': Normalize t 

type family (a :: [Factor *]) @~ (b :: [Factor *]) :: Constraint where ... infix 4 Source #

Check if two [Factor *]s should be considered to be equal

Equations

a @~ b = Normalize (a @- b) ~ '[] 

type family Reorder' (scrut :: ([Factor *], Maybe (Factor *))) (t :: [Factor *]) :: [Factor *] where ... Source #

Helper function in Reorder

Equations

Reorder' '(lst, Nothing) t = Reorder lst t 
Reorder' '(lst, Just elt) t = elt ': Reorder lst t 

type family Reorder (a :: [Factor *]) (b :: [Factor *]) :: [Factor *] where ... Source #

Reorders a to be the in the same order as b, putting entries not in b at the end

Reorder [A 1, B 2] [B 5, A 2] ==> [B 2, A 1]
Reorder [A 1, B 2, C 3] [C 2, A 8] ==> [C 3, A 1, B 2]
Reorder [A 1, B 2] [B 4, C 1, A 9] ==> [B 2, A 1]
Reorder x x ==> x
Reorder x [] ==> x
Reorder [] x ==> []

Equations

Reorder x x = x 
Reorder '[] x = '[] 
Reorder '[x] y = '[x] 
Reorder x '[] = x 
Reorder x (h ': t) = Reorder' (Extract h x) t 

type family Extract (s :: Factor *) (lst :: [Factor *]) :: ([Factor *], Maybe (Factor *)) where ... Source #

(Extract s lst) pulls the Factor that matches s out of lst, returning a diminished list and, possibly, the extracted Factor.

Extract A [A, B, C] ==> ([B, C], Just A
Extract F [A, B, C] ==> ([A, B, C], Nothing)

Equations

Extract s '[] = '('[], Nothing) 
Extract s (h ': t) = If (s $= h) '(t, Just h) '(h ': Fst (Extract s t), Snd (Extract s t)) 

type family (a :: Factor *) $= (b :: Factor *) :: Bool where ... infix 4 Source #

Do these Factors represent the same dimension?

Equations

(F n1 z1) $= (F n2 z2) = n1 == n2 
a $= b = False 

data Factor star Source #

This will only be used at the kind level. It holds a dimension or unit with its exponent.

Constructors

F star Z 

Instances

Instances details
UnitFactor ('[] :: [Factor Type]) Source # 
Instance details

Defined in Data.Metrology.Units

Read n => Read (Qu ('[] :: [Factor Type]) l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

readsPrec :: Int -> ReadS (Qu '[] l n) #

readList :: ReadS [Qu '[] l n] #

readPrec :: ReadPrec (Qu '[] l n) #

readListPrec :: ReadPrec [Qu '[] l n] #

Show n => Show (Qu ('[] :: [Factor Type]) l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

showsPrec :: Int -> Qu '[] l n -> ShowS #

show :: Qu '[] l n -> String #

showList :: [Qu '[] l n] -> ShowS #

(UnitFactor rest, Unit unit, SingI n) => UnitFactor ('F unit n ': rest) Source # 
Instance details

Defined in Data.Metrology.Units

Methods

canonicalConvRatioSpec :: Proxy ('F unit n ': rest) -> Rational

type family MkLCSU pairs where ... Source #

Make a local consistent set of units. The argument is a type-level list of tuple types, to be interpreted as an association list from dimensions to units. For example:

type MyLCSU = MkLCSU '[(Length, Foot), (Mass, Gram), (Time, Year)]

Equations

MkLCSU pairs = MkLCSU_ (UsePromotedTuples pairs) 

type family DefaultUnitOfDim (dim :: *) :: * Source #

Assign a default unit for a dimension. Necessary only when using default LCSUs.

Instances

Instances details
type DefaultUnitOfDim Dimensionless Source # 
Instance details

Defined in Data.Metrology.Units

type DefaultUnitOfDim (d :^ z) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DefaultUnitOfDim (d1 :/ d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DefaultUnitOfDim (d1 :* d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type family LookupList (keys :: [Factor *]) (map :: LCSU *) :: [Factor *] where ... Source #

Equations

LookupList '[] lcsu = '[] 
LookupList (F dim z ': rest) lcsu = F (Lookup dim lcsu) z ': LookupList rest lcsu 

type family Lookup (dim :: *) (lcsu :: LCSU *) :: * where ... Source #

Equations

Lookup dim (MkLCSU_ ('(dim, unit) ': rest)) = unit 
Lookup dim (MkLCSU_ ('(other, u) ': rest)) = Lookup dim (MkLCSU_ rest) 
Lookup dim DefaultLCSU = DefaultUnitOfDim dim 

data LCSU star Source #

Constructors

DefaultLCSU 

class Dimension dim Source #

This class is used to mark abstract dimensions, such as Length, or Mass.

Associated Types

type DimFactorsOf dim :: [Factor *] Source #

Retrieve a list of Factors representing the given dimension. Overriding the default of this type family should not be necessary in user code.

type DimFactorsOf dim = '[F dim One]

Instances

Instances details
Dimension Dimensionless Source # 
Instance details

Defined in Data.Metrology.Units

Associated Types

type DimFactorsOf Dimensionless :: [Factor Type] Source #

Dimension dim => Dimension (dim :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type DimFactorsOf (dim :^ power) :: [Factor Type] Source #

(Dimension d1, Dimension d2) => Dimension (d1 :/ d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type DimFactorsOf (d1 :/ d2) :: [Factor Type] Source #

(Dimension d1, Dimension d2) => Dimension (d1 :* d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type DimFactorsOf (d1 :* d2) :: [Factor Type] Source #

data Number Source #

The unit for unitless dimensioned quantities

Constructors

Number 

Instances

Instances details
Unit Number Source # 
Instance details

Defined in Data.Metrology.Units

type BaseUnit Number Source # 
Instance details

Defined in Data.Metrology.Units

type DimOfUnit Number Source # 
Instance details

Defined in Data.Metrology.Units

type UnitFactorsOf Number Source # 
Instance details

Defined in Data.Metrology.Units

data Dimensionless Source #

The dimension for the dimensionless quantities. It is also called "quantities of dimension one", but One is confusing with the type-level integer One.

Constructors

Dimensionless 

Instances

Instances details
Dimension Dimensionless Source # 
Instance details

Defined in Data.Metrology.Units

Associated Types

type DimFactorsOf Dimensionless :: [Factor Type] Source #

type DefaultUnitOfDim Dimensionless Source # 
Instance details

Defined in Data.Metrology.Units

type DimFactorsOf Dimensionless Source # 
Instance details

Defined in Data.Metrology.Units

class Units units => UnitFactor (units :: [Factor *]) Source #

Classifies well-formed list of unit factors, and permits calculating a conversion ratio for the purposes of LCSU conversions.

Minimal complete definition

canonicalConvRatioSpec

Instances

Instances details
UnitFactor ('[] :: [Factor Type]) Source # 
Instance details

Defined in Data.Metrology.Units

(UnitFactor rest, Unit unit, SingI n) => UnitFactor ('F unit n ': rest) Source # 
Instance details

Defined in Data.Metrology.Units

Methods

canonicalConvRatioSpec :: Proxy ('F unit n ': rest) -> Rational

type family BaseHasConvRatio unit where ... Source #

Essentially, a constraint that checks if a conversion ratio can be calculated for a BaseUnit of a unit.

Equations

BaseHasConvRatio unit = HasConvRatio (IsCanonical unit) unit 

type family CanonicalUnit' (base_unit :: *) (unit :: *) :: * where ... Source #

Helper function in CanonicalUnit

Equations

CanonicalUnit' Canonical unit = unit 
CanonicalUnit' base unit = CanonicalUnit' (BaseUnit base) base 

type CanonicalUnit (unit :: *) = CanonicalUnit' (BaseUnit unit) unit Source #

Get the canonical unit from a given unit. For example: CanonicalUnit Foot = Meter

type family IsCanonical (unit :: *) where ... Source #

Is this unit a canonical unit?

Equations

IsCanonical unit = BaseUnit unit == Canonical 

type family DimOfUnitIsConsistent unit :: Constraint where ... Source #

Check to make sure that a unit has the same dimension as its base unit, if any.

Equations

DimOfUnitIsConsistent unit = (Dimension (DimOfUnit unit), If (BaseUnit unit == Canonical) (() :: Constraint) (DimOfUnit unit ~ DimOfUnit (BaseUnit unit))) 

class DimOfUnitIsConsistent unit => Unit unit where Source #

Minimal complete definition

Nothing

Associated Types

type BaseUnit unit :: * Source #

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.

type DimOfUnit unit :: * Source #

The dimension that this unit is associated with. This needs to be defined only for canonical units; other units are necessarily of the same dimension as their base.

type DimOfUnit unit = DimOfUnit (BaseUnit unit)

type UnitFactorsOf unit :: [Factor *] Source #

The internal list of canonical units corresponding to this unit. Overriding the default should not be necessary in user code.

type UnitFactorsOf unit = If (IsCanonical unit) '[F unit One] (UnitFactorsOf (BaseUnit unit))

Methods

conversionRatio :: unit -> Rational Source #

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!

Instances

Instances details
Unit Number Source # 
Instance details

Defined in Data.Metrology.Units

((unit == Canonical) ~ 'False, Unit unit, UnitPrefix prefix) => Unit (prefix :@ unit) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (prefix :@ unit) Source #

type DimOfUnit (prefix :@ unit) Source #

type UnitFactorsOf (prefix :@ unit) :: [Factor Type] Source #

Methods

conversionRatio :: (prefix :@ unit) -> Rational Source #

canonicalConvRatio :: (prefix :@ unit) -> Rational

(Unit unit, SingI power) => Unit (unit :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (unit :^ power) Source #

type DimOfUnit (unit :^ power) Source #

type UnitFactorsOf (unit :^ power) :: [Factor Type] Source #

Methods

conversionRatio :: (unit :^ power) -> Rational Source #

canonicalConvRatio :: (unit :^ power) -> Rational

(Unit u1, Unit u2) => Unit (u1 :/ u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (u1 :/ u2) Source #

type DimOfUnit (u1 :/ u2) Source #

type UnitFactorsOf (u1 :/ u2) :: [Factor Type] Source #

Methods

conversionRatio :: (u1 :/ u2) -> Rational Source #

canonicalConvRatio :: (u1 :/ u2) -> Rational

(Unit u1, Unit u2) => Unit (u1 :* u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (u1 :* u2) Source #

type DimOfUnit (u1 :* u2) Source #

type UnitFactorsOf (u1 :* u2) :: [Factor Type] Source #

Methods

conversionRatio :: (u1 :* u2) -> Rational Source #

canonicalConvRatio :: (u1 :* u2) -> Rational

data Canonical Source #

Dummy type use just to label canonical units. It does not have a Unit instance.

type family (d :: *) %^ (z :: Z) :: * infixr 8 Source #

Exponentiate a quantity type to an integer

Instances

Instances details
type (Qu d l n) %^ z Source # 
Instance details

Defined in Data.Metrology.Qu

type (Qu d l n) %^ z = Qu (d @* z) l n

type family (d1 :: *) %/ (d2 :: *) :: * infixl 7 Source #

Divide two quantity types to produce a new one

Instances

Instances details
type (Qu d1 l n) %/ (Qu d2 l n) Source # 
Instance details

Defined in Data.Metrology.Qu

type (Qu d1 l n) %/ (Qu d2 l n) = Qu (d1 @- d2) l n

type family (d1 :: *) %* (d2 :: *) :: * infixl 7 Source #

Multiply two quantity types to produce a new one. For example:

type Velocity = Length %/ Time

Instances

Instances details
type (Qu d1 l n) %* (Qu d2 l n) Source # 
Instance details

Defined in Data.Metrology.Qu

type (Qu d1 l n) %* (Qu d2 l n) = Qu (d1 @+ d2) l n

type MkQu_ULN unit = Qu (DimFactorsOf (DimOfUnit unit)) Source #

Make a quantity type with a unit and LCSU with custom numerical type. The quantity will have the dimension corresponding to the unit.

type MkQu_U unit = Qu (DimFactorsOf (DimOfUnit unit)) DefaultLCSU Double Source #

Make a quantity type with a given unit. It will be stored as a Double. Note that the corresponding dimension must have an appropriate instance for DefaultUnitOfDim for this to work.

type MkQu_DLN dim = Qu (DimFactorsOf dim) Source #

Make a quantity type with a custom numerical type and LCSU.

type MkQu_D dim = Qu (DimFactorsOf dim) DefaultLCSU Double Source #

Make a quantity type capable of storing a value of a given unit. This uses a Double for storage of the value. For example:

data LengthDim = LengthDim
instance Dimension LengthDim
data Meter = Meter
instance Unit Meter where
  type BaseUnit Meter = Canonical
  type DimOfUnit Meter = LengthDim
type instance DefaultUnitOfDim LengthDim = Meter
type Length = MkQu_D LengthDim

Note that the dimension must have an instance for the type family DefaultUnitOfDim for this to work.

data Qu (a :: [Factor *]) (lcsu :: LCSU *) (n :: *) Source #

Qu adds a dimensional annotation to its numerical value type n. This is the representation for all quantities.

Instances

Instances details
Eq n => Eq (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

(==) :: Qu d l n -> Qu d l n -> Bool #

(/=) :: Qu d l n -> Qu d l n -> Bool #

(d ~ ('[] :: [Factor Type]), Floating n) => Floating (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

pi :: Qu d l n #

exp :: Qu d l n -> Qu d l n #

log :: Qu d l n -> Qu d l n #

sqrt :: Qu d l n -> Qu d l n #

(**) :: Qu d l n -> Qu d l n -> Qu d l n #

logBase :: Qu d l n -> Qu d l n -> Qu d l n #

sin :: Qu d l n -> Qu d l n #

cos :: Qu d l n -> Qu d l n #

tan :: Qu d l n -> Qu d l n #

asin :: Qu d l n -> Qu d l n #

acos :: Qu d l n -> Qu d l n #

atan :: Qu d l n -> Qu d l n #

sinh :: Qu d l n -> Qu d l n #

cosh :: Qu d l n -> Qu d l n #

tanh :: Qu d l n -> Qu d l n #

asinh :: Qu d l n -> Qu d l n #

acosh :: Qu d l n -> Qu d l n #

atanh :: Qu d l n -> Qu d l n #

log1p :: Qu d l n -> Qu d l n #

expm1 :: Qu d l n -> Qu d l n #

log1pexp :: Qu d l n -> Qu d l n #

log1mexp :: Qu d l n -> Qu d l n #

(d ~ ('[] :: [Factor Type]), Fractional n) => Fractional (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

(/) :: Qu d l n -> Qu d l n -> Qu d l n #

recip :: Qu d l n -> Qu d l n #

fromRational :: Rational -> Qu d l n #

(d ~ ('[] :: [Factor Type]), Num n) => Num (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

(+) :: Qu d l n -> Qu d l n -> Qu d l n #

(-) :: Qu d l n -> Qu d l n -> Qu d l n #

(*) :: Qu d l n -> Qu d l n -> Qu d l n #

negate :: Qu d l n -> Qu d l n #

abs :: Qu d l n -> Qu d l n #

signum :: Qu d l n -> Qu d l n #

fromInteger :: Integer -> Qu d l n #

Ord n => Ord (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

compare :: Qu d l n -> Qu d l n -> Ordering #

(<) :: Qu d l n -> Qu d l n -> Bool #

(<=) :: Qu d l n -> Qu d l n -> Bool #

(>) :: Qu d l n -> Qu d l n -> Bool #

(>=) :: Qu d l n -> Qu d l n -> Bool #

max :: Qu d l n -> Qu d l n -> Qu d l n #

min :: Qu d l n -> Qu d l n -> Qu d l n #

Read n => Read (Qu ('[] :: [Factor Type]) l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

readsPrec :: Int -> ReadS (Qu '[] l n) #

readList :: ReadS [Qu '[] l n] #

readPrec :: ReadPrec (Qu '[] l n) #

readListPrec :: ReadPrec [Qu '[] l n] #

(d ~ ('[] :: [Factor Type]), Real n) => Real (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

toRational :: Qu d l n -> Rational #

(d ~ ('[] :: [Factor Type]), RealFloat n) => RealFloat (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

floatRadix :: Qu d l n -> Integer #

floatDigits :: Qu d l n -> Int #

floatRange :: Qu d l n -> (Int, Int) #

decodeFloat :: Qu d l n -> (Integer, Int) #

encodeFloat :: Integer -> Int -> Qu d l n #

exponent :: Qu d l n -> Int #

significand :: Qu d l n -> Qu d l n #

scaleFloat :: Int -> Qu d l n -> Qu d l n #

isNaN :: Qu d l n -> Bool #

isInfinite :: Qu d l n -> Bool #

isDenormalized :: Qu d l n -> Bool #

isNegativeZero :: Qu d l n -> Bool #

isIEEE :: Qu d l n -> Bool #

atan2 :: Qu d l n -> Qu d l n -> Qu d l n #

(d ~ ('[] :: [Factor Type]), RealFrac n) => RealFrac (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

properFraction :: Integral b => Qu d l n -> (b, Qu d l n) #

truncate :: Integral b => Qu d l n -> b #

round :: Integral b => Qu d l n -> b #

ceiling :: Integral b => Qu d l n -> b #

floor :: Integral b => Qu d l n -> b #

Show n => Show (Qu ('[] :: [Factor Type]) l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

showsPrec :: Int -> Qu '[] l n -> ShowS #

show :: Qu '[] l n -> String #

showList :: [Qu '[] l n] -> ShowS #

(ShowUnitFactor (LookupList dims lcsu), Show n) => Show (Qu dims lcsu n) Source # 
Instance details

Defined in Data.Metrology.Show

Methods

showsPrec :: Int -> Qu dims lcsu n -> ShowS #

show :: Qu dims lcsu n -> String #

showList :: [Qu dims lcsu n] -> ShowS #

NFData n => NFData (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

rnf :: Qu d l n -> () #

VectorSpace n => VectorSpace (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Associated Types

type Scalar (Qu d l n) #

Methods

(*^) :: Scalar (Qu d l n) -> Qu d l n -> Qu d l n #

AdditiveGroup n => AdditiveGroup (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

Methods

zeroV :: Qu d l n #

(^+^) :: Qu d l n -> Qu d l n -> Qu d l n #

negateV :: Qu d l n -> Qu d l n #

(^-^) :: Qu d l n -> Qu d l n -> Qu d l n #

ValidDL d l => Quantity (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Quantity

Associated Types

type QuantityUnit (Qu d l n) Source #

type QuantityLCSU (Qu d l n) :: LCSU Type Source #

type QuantityRep (Qu d l n) Source #

Methods

fromQuantity :: QuantityQu (Qu d l n) -> Qu d l n Source #

toQuantity :: Qu d l n -> QuantityQu (Qu d l n) Source #

type Scalar (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Qu

type Scalar (Qu d l n) = Scalar n
type QuantityUnit (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Quantity

type QuantityUnit (Qu d l n) = UnitOfDimFactors d l
type QuantityLCSU (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Quantity

type QuantityLCSU (Qu d l n) = l
type QuantityRep (Qu d l n) Source # 
Instance details

Defined in Data.Metrology.Quantity

type QuantityRep (Qu d l n) = n
type (Qu d l n) %^ z Source # 
Instance details

Defined in Data.Metrology.Qu

type (Qu d l n) %^ z = Qu (d @* z) l n
type (Qu d1 l n) %/ (Qu d2 l n) Source # 
Instance details

Defined in Data.Metrology.Qu

type (Qu d1 l n) %/ (Qu d2 l n) = Qu (d1 @- d2) l n
type (Qu d1 l n) %* (Qu d2 l n) Source # 
Instance details

Defined in Data.Metrology.Qu

type (Qu d1 l n) %* (Qu d2 l n) = Qu (d1 @+ d2) l n

quantity :: n -> Qu '[] l n Source #

Convert a raw number into a unitless dimensioned quantity

(|*|) :: Num n => Qu a l n -> Qu b l n -> Qu (Normalize (a @+ b)) l n infixl 7 Source #

Multiply two quantities

(|/|) :: Fractional n => Qu a l n -> Qu b l n -> Qu (Normalize (a @- b)) l n infixl 7 Source #

Divide two quantities

(|^) :: (NonNegative z, Num n) => Qu a l n -> Sing z -> Qu (a @* z) l n infixr 8 Source #

Raise a quantity to a integer power, knowing at compile time that the integer is non-negative.

(|^^) :: Fractional n => Qu a l n -> Sing z -> Qu (a @* z) l n infixr 8 Source #

Raise a quantity to a integer power known at compile time

qNthRoot :: ((Zero < z) ~ True, Floating n) => Sing z -> Qu a l n -> Qu (a @/ z) l n Source #

Take the n'th root of a quantity, where n is known at compile time

qCompare :: (d1 @~ d2, Ord n) => Qu d1 l n -> Qu d2 l n -> Ordering Source #

Compare two quantities

(|<|) :: (d1 @~ d2, Ord n) => Qu d1 l n -> Qu d2 l n -> Bool infix 4 Source #

Check if one quantity is less than a compatible one

(|>|) :: (d1 @~ d2, Ord n) => Qu d1 l n -> Qu d2 l n -> Bool infix 4 Source #

Check if one quantity is greater than a compatible one

(|<=|) :: (d1 @~ d2, Ord n) => Qu d1 l n -> Qu d2 l n -> Bool infix 4 Source #

Check if one quantity is less than or equal to a compatible one

(|>=|) :: (d1 @~ d2, Ord n) => Qu d1 l n -> Qu d2 l n -> Bool infix 4 Source #

Check if one quantity is greater than or equal to a compatible one

(|==|) :: (d1 @~ d2, Eq n) => Qu d1 l n -> Qu d2 l n -> Bool infix 4 Source #

Check if two quantities are equal (uses the equality of the underlying numerical type)

(|/=|) :: (d1 @~ d2, Eq n) => Qu d1 l n -> Qu d2 l n -> Bool infix 4 Source #

Check if two quantities are not equal

qApprox infix 4 Source #

Arguments

:: (d0 @~ d1, d0 @~ d2, Num n, Ord n) 
=> Qu d0 l n

epsilon

-> Qu d1 l n

left hand side

-> Qu d2 l n

right hand side

-> Bool 

Compare two compatible quantities for approximate equality. If the difference between the left hand side and the right hand side arguments are less than or equal to the epsilon, they are considered equal.

qNapprox infix 4 Source #

Arguments

:: (d0 @~ d1, d0 @~ d2, Num n, Ord n) 
=> Qu d0 l n

epsilon

-> Qu d1 l n

left hand side

-> Qu d2 l n

right hand side

-> Bool 

Compare two compatible quantities for approixmate inequality. qNapprox e a b = not $ qApprox e a b

(/|) :: Fractional n => n -> Qu b l n -> Qu (Normalize ('[] @- b)) l n infixl 7 Source #

Divide a scalar by a quantity

qSq :: Num n => Qu a l n -> Qu (Normalize (a @+ a)) l n Source #

Square a quantity

qCube :: Num n => Qu a l n -> Qu (Normalize (Normalize (a @+ a) @+ a)) l n Source #

Cube a quantity

qSqrt :: Floating n => Qu a l n -> Qu (a @/ Two) l n Source #

Take the square root of a quantity

qCubeRoot :: Floating n => Qu a l n -> Qu (a @/ Three) l n Source #

Take the cubic root of a quantity

defaultLCSU :: Qu dim DefaultLCSU n -> Qu dim DefaultLCSU n Source #

Use this to choose a default LCSU for a dimensioned quantity. The default LCSU uses the DefaultUnitOfDim representation for each dimension.

unity :: Num n => Qu '[] l n Source #

The number 1, expressed as a unitless dimensioned quantity.

redim :: d @~ e => Qu d l n -> Qu e l n Source #

Cast between equivalent dimension within the same CSU. for example [kg m s] and [s m kg]. See the README for more info.

class UnitPrefix prefix where Source #

A class for user-defined prefixes

Methods

multiplier :: Fractional f => prefix -> f Source #

This should return the desired multiplier for the prefix being defined. This function must not inspect its argument.

data prefix :@ unit infixr 9 Source #

Multiply a conversion ratio by some constant. Used for defining prefixes.

Constructors

prefix :@ unit infixr 9 

Instances

Instances details
(Show prefix, Show unit) => Show (prefix :@ unit) Source # 
Instance details

Defined in Data.Metrology.Combinators

Methods

showsPrec :: Int -> (prefix :@ unit) -> ShowS #

show :: (prefix :@ unit) -> String #

showList :: [prefix :@ unit] -> ShowS #

((unit == Canonical) ~ 'False, Unit unit, UnitPrefix prefix) => Unit (prefix :@ unit) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (prefix :@ unit) Source #

type DimOfUnit (prefix :@ unit) Source #

type UnitFactorsOf (prefix :@ unit) :: [Factor Type] Source #

Methods

conversionRatio :: (prefix :@ unit) -> Rational Source #

canonicalConvRatio :: (prefix :@ unit) -> Rational

type BaseUnit (prefix :@ unit) Source # 
Instance details

Defined in Data.Metrology.Combinators

type BaseUnit (prefix :@ unit) = unit
type DimOfUnit (prefix :@ unit) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimOfUnit (prefix :@ unit) = DimOfUnit (BaseUnit (prefix :@ unit))
type UnitFactorsOf (prefix :@ unit) Source # 
Instance details

Defined in Data.Metrology.Combinators

type UnitFactorsOf (prefix :@ unit) = If (IsCanonical (prefix :@ unit)) '['F (prefix :@ unit) One] (UnitFactorsOf (BaseUnit (prefix :@ unit)))

data unit :^ (power :: Z) infixr 8 Source #

Raise a unit to a power, known at compile time

Constructors

unit :^ (Sing power) infixr 8 

Instances

Instances details
(Show u1, SingI power) => Show (u1 :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

Methods

showsPrec :: Int -> (u1 :^ power) -> ShowS #

show :: (u1 :^ power) -> String #

showList :: [u1 :^ power] -> ShowS #

Dimension dim => Dimension (dim :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type DimFactorsOf (dim :^ power) :: [Factor Type] Source #

(Unit unit, SingI power) => Unit (unit :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (unit :^ power) Source #

type DimOfUnit (unit :^ power) Source #

type UnitFactorsOf (unit :^ power) :: [Factor Type] Source #

Methods

conversionRatio :: (unit :^ power) -> Rational Source #

canonicalConvRatio :: (unit :^ power) -> Rational

type DefaultUnitOfDim (d :^ z) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimFactorsOf (dim :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimFactorsOf (dim :^ power) = Normalize (DimFactorsOf dim @* power)
type BaseUnit (unit :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

type BaseUnit (unit :^ power) = Canonical
type DimOfUnit (unit :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimOfUnit (unit :^ power) = DimOfUnit unit :^ power
type UnitFactorsOf (unit :^ power) Source # 
Instance details

Defined in Data.Metrology.Combinators

type UnitFactorsOf (unit :^ power) = Normalize (UnitFactorsOf unit @* power)

data u1 :/ u2 infixl 7 Source #

Divide two units to get another unit

Constructors

u1 :/ u2 infixl 7 

Instances

Instances details
(Show u1, Show u2) => Show (u1 :/ u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Methods

showsPrec :: Int -> (u1 :/ u2) -> ShowS #

show :: (u1 :/ u2) -> String #

showList :: [u1 :/ u2] -> ShowS #

(Dimension d1, Dimension d2) => Dimension (d1 :/ d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type DimFactorsOf (d1 :/ d2) :: [Factor Type] Source #

(Unit u1, Unit u2) => Unit (u1 :/ u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (u1 :/ u2) Source #

type DimOfUnit (u1 :/ u2) Source #

type UnitFactorsOf (u1 :/ u2) :: [Factor Type] Source #

Methods

conversionRatio :: (u1 :/ u2) -> Rational Source #

canonicalConvRatio :: (u1 :/ u2) -> Rational

type DefaultUnitOfDim (d1 :/ d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimFactorsOf (d1 :/ d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type BaseUnit (u1 :/ u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type BaseUnit (u1 :/ u2) = Canonical
type DimOfUnit (u1 :/ u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimOfUnit (u1 :/ u2) = DimOfUnit u1 :/ DimOfUnit u2
type UnitFactorsOf (u1 :/ u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

data u1 :* u2 infixl 7 Source #

Multiply two units to get another unit. For example: type MetersSquared = Meter :* Meter

Constructors

u1 :* u2 infixl 7 

Instances

Instances details
(Show u1, Show u2) => Show (u1 :* u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Methods

showsPrec :: Int -> (u1 :* u2) -> ShowS #

show :: (u1 :* u2) -> String #

showList :: [u1 :* u2] -> ShowS #

(Dimension d1, Dimension d2) => Dimension (d1 :* d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type DimFactorsOf (d1 :* d2) :: [Factor Type] Source #

(Unit u1, Unit u2) => Unit (u1 :* u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

Associated Types

type BaseUnit (u1 :* u2) Source #

type DimOfUnit (u1 :* u2) Source #

type UnitFactorsOf (u1 :* u2) :: [Factor Type] Source #

Methods

conversionRatio :: (u1 :* u2) -> Rational Source #

canonicalConvRatio :: (u1 :* u2) -> Rational

type DefaultUnitOfDim (d1 :* d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimFactorsOf (d1 :* d2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type BaseUnit (u1 :* u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type BaseUnit (u1 :* u2) = Canonical
type DimOfUnit (u1 :* u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type DimOfUnit (u1 :* u2) = DimOfUnit u1 :* DimOfUnit u2
type UnitFactorsOf (u1 :* u2) Source # 
Instance details

Defined in Data.Metrology.Combinators

type family DefaultConvertibleLCSU_U (unit :: *) (l :: LCSU *) :: Constraint where ... Source #

Check if the DefaultLCSU can convert into the given one, at the given unit.

type family DefaultConvertibleLCSU_D (dim :: *) (l :: LCSU *) :: Constraint where ... Source #

Check if the DefaultLCSU can convert into the given one, at the given dimension.

type family CompatibleDim (lcsu :: LCSU *) (dim :: *) :: Constraint where ... Source #

Check if an LCSU can express the given dimension

Equations

CompatibleDim lcsu dim = (UnitFactor (LookupList (DimFactorsOf dim) lcsu), DimOfUnit (Lookup dim lcsu) ~ dim) 

type family CompatibleUnit (lcsu :: LCSU *) (unit :: *) :: Constraint where ... Source #

Check if an LCSU has consistent entries for the given unit. i.e. can the lcsu describe the unit?

Equations

CompatibleUnit lcsu unit = (ValidDLU (DimFactorsOf (DimOfUnit unit)) lcsu unit, UnitFactor (LookupList (DimFactorsOf (DimOfUnit unit)) lcsu)) 

type family CanonicalUnitsOfFactors (fs :: [Factor *]) :: [*] where ... Source #

Given a list of unit factors, extract out the canonical units they are based on.

type family (units1 :: [Factor *]) *~ (units2 :: [Factor *]) :: Constraint where ... infix 4 Source #

Check if two [Factor *]s, representing units, should be considered to be equal

Equations

units1 *~ units2 = CanonicalUnitsOfFactors units1 `SetEqual` CanonicalUnitsOfFactors units2 

type family ConvertibleLCSUs_D (dim :: *) (l1 :: LCSU *) (l2 :: LCSU *) :: Constraint where ... Source #

Like ConvertibleLCSUs, but takes a dimension, not a dimension factors.

Equations

ConvertibleLCSUs_D dim l1 l2 = ConvertibleLCSUs (DimFactorsOf dim) l1 l2 

type family ConvertibleLCSUs (dfactors :: [Factor *]) (l1 :: LCSU *) (l2 :: LCSU *) :: Constraint where ... Source #

Are two LCSUs inter-convertible at the given dimension?

Equations

ConvertibleLCSUs dfactors l1 l2 = (LookupList dfactors l1 *~ LookupList dfactors l2, ValidDL dfactors l1, ValidDL dfactors l2, UnitFactor (LookupList dfactors l1), UnitFactor (LookupList dfactors l2)) 

type family ValidDL (dfactors :: [Factor *]) (lcsu :: LCSU *) :: Constraint where ... Source #

Check if a (dimension factors, LCSU) pair are valid to be used together. This checks that each dimension maps to a unit of the correct dimension.

Equations

ValidDL dfactors lcsu = ValidDLU dfactors lcsu (UnitOfDimFactors dfactors lcsu) 

type family ValidDLU (dfactors :: [Factor *]) (lcsu :: LCSU *) (unit :: *) where ... Source #

Check if a (dimension factors, LCSU, unit) triple are all valid to be used together.

Equations

ValidDLU dfactors lcsu unit = (dfactors ~ DimFactorsOf (DimOfUnit unit), UnitFactor (LookupList dfactors lcsu), Unit unit, UnitFactorsOf unit *~ LookupList dfactors lcsu) 

type family UnitOfDimFactors (dims :: [Factor *]) (lcsu :: LCSU *) :: * where ... Source #

Extract a unit from a dimension factor list and an LCSU

Equations

UnitOfDimFactors dims lcsu = MultUnitFactors (LookupList dims lcsu) 

type family MultUnitFactors (facts :: [Factor *]) where ... Source #

Extract a unit specifier from a list of factors

Equations

MultUnitFactors '[] = Number 
MultUnitFactors (F unit z ': units) = (unit :^ z) :* MultUnitFactors units 

type family MultDimFactors (facts :: [Factor *]) where ... Source #

Extract a dimension specifier from a list of factors

Equations

MultDimFactors '[] = Dimensionless 
MultDimFactors (F d z ': ds) = (d :^ z) :* MultDimFactors ds 

showIn :: (ValidDLU dim lcsu unit, Fractional n, Show unit, Show n) => Qu dim lcsu n -> unit -> String infix 1 Source #

Show a dimensioned quantity in a given unit. (The default Show instance always uses units as specified in the LCSU.)

convert :: forall d l1 l2 n. (ConvertibleLCSUs d l1 l2, Fractional n) => Qu d l1 n -> Qu d l2 n Source #

Dimension-keeping cast between different CSUs.

constant :: (d @~ e, ConvertibleLCSUs e DefaultLCSU l, Fractional n) => Qu d DefaultLCSU n -> Qu e l n Source #

Compute the argument in the DefaultLCSU, and present the result as lcsu-polymorphic dimension-polymorphic value. Named constant because one of its dominant usecase is to inject constant quantities into dimension-polymorphic expressions.

zero :: Num n => Qu dimspec l n Source #

The number 0, polymorphic in its dimension. Use of this will often require a type annotation.

(|+|) :: (d1 @~ d2, Num n) => Qu d1 l n -> Qu d2 l n -> Qu d1 l n infixl 6 Source #

Add two compatible quantities

(|-|) :: (d1 @~ d2, Num n) => Qu d1 l n -> Qu d2 l n -> Qu d1 l n infixl 6 Source #

Subtract two compatible quantities

qSum :: (Foldable f, Num n) => f (Qu d l n) -> Qu d l n Source #

Take the sum of a list of quantities

qNegate :: Num n => Qu d l n -> Qu d l n Source #

Negate a quantity

(*|) :: Num n => n -> Qu b l n -> Qu b l n infixl 7 Source #

Multiply a quantity by a scalar from the left

(|*) :: Num n => Qu a l n -> n -> Qu a l n infixl 7 Source #

Multiply a quantity by a scalar from the right

(|/) :: Fractional n => Qu a l n -> n -> Qu a l n infixl 7 Source #

Divide a quantity by a scalar