This module defines data types and functions to handle physical units.

#Prefix Source

data Prefix

A number that represents a power of ten/two as a prefix for a unit.


#DerivedUnit Source

data DerivedUnit

A generic physical unit. The Semigroup/Monoid instance implements multiplication of units.

Implementation detail: A DerivedUnit is a product of BaseUnits, raised to arbitrary powers. Each factor also has a Prefix value which represents a numerical prefix as a power of ten or two.


#decimalPrefix Source

decimalPrefix :: Number -> DerivedUnit -> DerivedUnit

Add a given decimal prefix value to a unit: withDecimal 3.0 meter = kilo meter.

#binaryPrefix Source

binaryPrefix :: Number -> DerivedUnit -> DerivedUnit

Add a given binary prefix value to a unit: withDecimal 10.0 byte = kibi byte.

#removePrefix Source

removePrefix :: DerivedUnit -> DerivedUnit

Remove all prefix values from the unit:

removePrefix (kilo meter <> milli second) = meter <> second

#simplify Source

simplify :: DerivedUnit -> DerivedUnit

Simplify the internal representation of a DerivedUnit by merging base units of the same type. For example, m·s·m will by simplified to m²·s.

#splitByDimension Source

splitByDimension :: DerivedUnit -> List (Tuple DerivedUnit DerivedUnit)

Split up a physical unit into several parts that belong to the same physical dimension (length, time, ...). In the first component, the returned tuples contain a 'target' unit, to which this group can be converted. In the second component, the original group is returned.

#baseRepresentation Source

baseRepresentation :: DerivedUnit -> List DerivedUnit

Return a representation of the DerivedUnit in terms of base units, split by physical dimension.

#makeStandard Source

makeStandard :: String -> String -> DerivedUnit

Helper function to create a standard unit.

#makeNonStandard Source

makeNonStandard :: String -> String -> Number -> DerivedUnit -> DerivedUnit

Helper function to create a non-standard unit.

#toStandardUnit Source

toStandardUnit :: DerivedUnit -> Tuple DerivedUnit ConversionFactor

Convert all contained units to standard units and return the global conversion factor.

#prefixName Source

prefixName :: Prefix -> Maybe String

Get the name of a SI-prefix.

#toString Source

toString :: DerivedUnit -> String

A human-readable String representation of a DerivedUnit.

#power Source

power :: DerivedUnit -> Number -> DerivedUnit

Raise a unit to the given power.

#(.^) Source

Operator alias for Data.Units.power (left-associative / precedence 9)

#divideUnits Source

divideUnits :: DerivedUnit -> DerivedUnit -> DerivedUnit

Divide two units.

#(./) Source

Operator alias for Data.Units.divideUnits (left-associative / precedence 6)

#unity Source

unity :: DerivedUnit

A DerivedUnit corresponding to 1, i.e. the unit of scalar (or dimensionless) values.