Data.Units
- Package
- purescript-quantities
- Repository
- sharkdp/purescript-quantities
This module defines data types and functions to handle physical units.
#DerivedUnit Source
data DerivedUnitA 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.
Instances
#withPrefix Source
withPrefix :: Number -> DerivedUnit -> DerivedUnitAdd a given prefix value to a unit: withPrefix 3.0 meter = kilo meter.
#removePrefix Source
removePrefix :: DerivedUnit -> DerivedUnitRemove all prefix values from the unit:
removePrefix (kilo meter <> milli second) = meter <> second
#simplify Source
simplify :: DerivedUnit -> DerivedUnitSimplify 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 units 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 DerivedUnitReturn a representation of the DerivedUnit in terms of base units, split
by physical dimension.
#makeStandard Source
makeStandard :: String -> String -> DerivedUnitHelper function to create a standard unit.
#makeNonStandard Source
makeNonStandard :: String -> String -> Number -> DerivedUnit -> DerivedUnitHelper function to create a non-standard unit.
#toStandardUnit Source
toStandardUnit :: DerivedUnit -> Tuple DerivedUnit ConversionFactorConvert all contained units to standard units and return the global conversion factor.
#toString Source
toString :: DerivedUnit -> StringA human-readable String representation of a DerivedUnit.
#power Source
power :: DerivedUnit -> Number -> DerivedUnitRaise a unit to the given power.
#divideUnits Source
divideUnits :: DerivedUnit -> DerivedUnit -> DerivedUnitDivide two units.
#unity Source
unity :: DerivedUnitA DerivedUnit corresponding to 1, i.e. the unit of scalar
(or dimensionless) values.
#atto Source
atto :: DerivedUnit -> DerivedUnit#femto Source
femto :: DerivedUnit -> DerivedUnit#pico Source
pico :: DerivedUnit -> DerivedUnit#nano Source
nano :: DerivedUnit -> DerivedUnit#micro Source
micro :: DerivedUnit -> DerivedUnit#milli Source
milli :: DerivedUnit -> DerivedUnit#centi Source
centi :: DerivedUnit -> DerivedUnit#deci Source
deci :: DerivedUnit -> DerivedUnit#hecto Source
hecto :: DerivedUnit -> DerivedUnit#kilo Source
kilo :: DerivedUnit -> DerivedUnit#mega Source
mega :: DerivedUnit -> DerivedUnit#giga Source
giga :: DerivedUnit -> DerivedUnit#tera Source
tera :: DerivedUnit -> DerivedUnit#peta Source
peta :: DerivedUnit -> DerivedUnit#exa Source
exa :: DerivedUnit -> DerivedUnit