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

Safe HaskellSafe
LanguageHaskell2010

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 -> Double Source

Extract a value in the given units.

value val units
value (2.54 * cm) in'

Distance

m :: Value Source

Meters.

cm :: Value Source

Centimeters.

mm :: Value Source

Millimeters.

km :: Value Source

Kilometers.

in' :: Value Source

Inches.

ft :: Value Source

Feet.

mi :: Value Source

Miles.

Area

cm2 :: Value Source

Centimeters ^ 2.

in2 :: Value Source

Inches ^ 2.

Volume

cm3 :: Value Source

Centimeters ^ 3.

ml :: Value Source

Milliliters.

l :: Value Source

Liters.

in3 :: Value Source

Inches ^ 3.

gal :: Value Source

Gallons.

Mass

kg :: Value Source

Kilograms.

g :: Value Source

Grams.

mg :: Value Source

Milligrams.

Force

n :: Value Source

Newtons.

lbs :: Value Source

Pounds.

Rotation

rev :: Value Source

Revolutions.

Speed

mph :: Value Source

Miles per hour.

kph :: Value Source

Kilometers per hour.

Rotational Rate

rpm :: Value Source

Revolutions per minute.

Time

s :: Value Source

Seconds.

ns :: Value Source

Nanoseconds.

us :: Value Source

Microseconds.

ms :: Value Source

Milliseconds.

min' :: Value Source

Minutes.

h :: Value Source

Hours.

Energy

j :: Value Source

Joules.

btu :: Value Source

BTUs.

Power

hp :: Value Source

Horsepower.

w :: Value Source

Watts.

kw :: Value Source

Kilowatts.

Pressure

psi :: Value Source

Pounds per inch ^ 2.

Flow

gpm :: Value Source

Gallons per minute.

lpm :: Value Source

Liters per minute.

Misc

s2 :: Value Source

Seconds ^ 2.

radsPerRev :: Value Source

Radians per revolution: 2 * pi / rev