Purescript types and functions for managing units of measure at runtime.
The API and implementation are currently experimental, subject to change, and open to suggestion.
Adding 4 meters to 2 seconds doesn't make sense but is easy to do by mistake when
both quantities are represented by simple Number
s. For correct
implementation, understanding both a value and its significance is essential.
This library provides functionality for performing mathematical operations and tracking the dimensionality of results along the way. Any operation that does not make sense dimensionally returns an error type that is propagated through subsequent operations. Conversion between units of the same dimensionality is easy.
This library provides two pieces of functionality.
Data.Units.Core
defines types and functions for definingDimensions
andQuantities
that represent values in thoseDimensions
. For example, time is aDimension
, and 1 second is aQuantity
of time. The functionality included in this module is general and allows the user to define his or her own dimension sets, do math and unit conversion with them, and examine results. For example, possible dimensions could include sales, points, coverage area, reviews, etc.Data.Units.Physical.SI
uses the functionalty inData.Units.Core
to define the SI set of dimensions (length, time, amount, current, mass, temperature, and luminous intensity) as well as the standard units of each (meter, second, mol, etc.).
Future additions include more physical units and possibly additional dimension standards.
Example usage is provided in the test
directory.