Data.Units
- Package
- purescript-quantities
- Repository
- sharkdp/purescript-quantities
This module defines data types and functions to handle physical units.
#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.
Instances
#withPrefix Source
withPrefix :: Number -> DerivedUnit -> DerivedUnit
Add a given prefix value to a unit: withPrefix 3.0 meter = kilo meter
.
#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 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 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.
#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.
#divideUnits Source
divideUnits :: DerivedUnit -> DerivedUnit -> DerivedUnit
Divide two units.
#unity Source
unity :: DerivedUnit
A 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