Safe Haskell | Safe-Inferred |
---|
A numeric type to manage engineering units.
Provides automatic unit conversion:
> print $ value (1 * h + 1 * min') s -- Time in seconds of 1 hour + 1 minute. 3660.0
Automatic unit reduction:
> print $ value (20 * gpm * 10 * min') gal -- Note the minutes cancel each other out. 200.0
And consistency checking:
> print $ value (22 * mph + 3 gal) mph -- Note that a speed (m/s) is inconsistent with a volume (m^3). *** Exception: Incompatible units: [M]/[S] /= [M,M,M]/[]
And defining new units is easy:
-- | Millimeters, a measure of distance. mm :: Value mm = 0.001 * m
-- | Joules, a measure of energy. j :: Value j = n * m
- data Value
- value :: Value -> Value -> Double
- m :: Value
- cm :: Value
- in' :: Value
- ft :: Value
- mi :: Value
- cm2 :: Value
- in2 :: Value
- cm3 :: Value
- in3 :: Value
- gal :: Value
- kg :: Value
- n :: Value
- lbs :: Value
- rev :: Value
- mph :: Value
- rpm :: Value
- s :: Value
- min' :: Value
- h :: Value
- hp :: Value
- w :: Value
- kw :: Value
- psi :: Value
- bar :: Value
- gpm :: Value
- s2 :: Value
- radsPerRev :: Value
Documentation
A value is a number and its associated units.
Distance
Area
Volume
Mass
Force
Rotation
Speed
Rotational Rate
Time
Power
Pressure
Flow
Other
Radians per revolution: 2 * pi / rev