engineering-units-0.0.1: A numeric type for managing and automating engineering units.

Safe HaskellSafe-Inferred

Data.EngineeringUnits

Contents

Description

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 speed (m/s) is inconsistent with volume (m^3).
 *** Exception: Incompatible units: [M]/[S] /= [M,M,M]/[]

And defining new units is easy:

 -- | Millimeters, a measure of distance, is 1/1000 of a meter.
 mm :: Value
 mm = 0.001 * m
 -- | Joules, a measure of energy, is one newton meter.
 j :: Value
 j = n * m

Synopsis

Documentation

data Value Source

A value is a number and its associated units.

value :: Value -> Value -> DoubleSource

Extract a value in the given units.

 value val units
 value (2.54 * cm) in'

Distance

m :: ValueSource

Meters.

cm :: ValueSource

Centimeters.

mm :: ValueSource

Millimeters.

km :: ValueSource

Kilometers.

in' :: ValueSource

Inches.

ft :: ValueSource

Feet.

mi :: ValueSource

Miles.

Area

cm2 :: ValueSource

Centimeters ^ 2.

in2 :: ValueSource

Inches ^ 2.

Volume

cm3 :: ValueSource

Centimeters ^ 3.

ml :: ValueSource

Milliliters.

l :: ValueSource

Liters.

in3 :: ValueSource

Inches ^ 3.

gal :: ValueSource

Gallons.

Mass

kg :: ValueSource

Kilograms.

g :: ValueSource

Grams.

mg :: ValueSource

Milligrams.

Force

n :: ValueSource

Newtons.

lbs :: ValueSource

Pounds.

Rotation

rev :: ValueSource

Revolutions.

Speed

mph :: ValueSource

Miles per hour.

kph :: ValueSource

Kilometers per hour.

Rotational Rate

rpm :: ValueSource

Revolutions per minute.

Time

s :: ValueSource

Seconds.

min' :: ValueSource

Minutes.

h :: ValueSource

Hours.

Energy

j :: ValueSource

Joules.

btu :: ValueSource

BTUs.

Power

hp :: ValueSource

Horsepower.

w :: ValueSource

Watts.

kw :: ValueSource

Kilowatts.

Pressure

psi :: ValueSource

Pounds per inch ^ 2.

Flow

gpm :: ValueSource

Gallons per minute.

lpm :: ValueSource

Liters per minute.

Misc

s2 :: ValueSource

Seconds ^ 2.

radsPerRev :: ValueSource

Radians per revolution: 2 * pi / rev