dimensional

This library provides statically-checked dimensional arithmetic for physical quantities, using the 7 SI base dimensions.

Data kinds and closed type families provide a flexible, safe, and discoverable implementation that leads to largely self-documenting client code.

Build Status Hackage Version

Usage

Simply importing Numeric.Units.Dimensional.Prelude provides access to dimensional arithmetic opertors, SI units and other common units accepted for use with the SI, and convenient aliases for quantities with commonly used dimensions.

The Unit d a type represents a unit with dimension d, whose conversion factor to the coherent SI base unit of the corresponding dimension is represented by a value of type a. a is commonly chosen to be Double, but can be any Floating type. Where possible, support is also provided for Fractional or Num values.

Similarly, the Quantity d a type represents a quantity with dimension d, whose numeric value is of type a. Aliases allow the use of, e.g., Length Double to mean Quantity DLength Double. A complete list of available aliases is given in the haddock documentation for the Numeric.Units.Dimensional.Quantities.

{-# LANGUAGE NoImplicitPrelude #-}

import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.NonSI (gee)

radiusOfEarth :: Length Double
radiusOfEarth = 6371 *~ kilo meter

massOfEarth :: Mass Double
massOfEarth = 5.97e24 *~ kilo gram

g :: GravitationalParameter Double
g = 6.67384e-11 *~ (meter^pos3 * (kilo gram)^neg1 * second^neg2)

gravitationalFieldStrength :: Mass a -> Length a -> Acceleration a
gravitationalFieldStrength m r = g * m / r^pos2

approximateAccelerationDueToGravityOnEarth = gravitationalFieldStrength massOfEarth radiusOfEarth

differenceFromStandardValue = approximateAccelerationDueToGravityOnEarth /~ gee

Contributing

For project information (issues, updates, wiki, examples) see: https://github.com/bjornbm/dimensional-dk

Changes

1.0.1.0 (2015-11)

  • Added Numeric.Units.Dimensional.Coercion module.
  • Bumped exact-pi dependency to < 0.5.
  • Restored changelog.
  • Addressed issues with documentation.

1.0.0.0 (2015-11)

  • Changed to DataKinds and ClosedTypeFamilies encoding of dimensions.
  • Added names and exact values to Units.
  • Added AnyUnit and AnyQuantity for quantities whose dimension is statically unknown.
  • Added Storable and Unbox instances for Quantity.
  • Added dimensionally-polymorphic siUnit for the coherent SI base unit of any dimension.
  • Added some additional units.

0.13.0.2 (2015-04)

  • Corrected definition of lumen.

0.13.0.1 (2014-09)

  • Bumped time dependency to < 1.6.

0.13 (2014-02)

  • Bump major version (should have been done in previous version).

0.12.3 (2014-02)

  • Bump numtype dependency to 1.1 (GHC 7.8.1 compatibility fix).
  • Added Torque.
  • Added D.. for the type synonym quantities (e.g., Angle).

0.12.2 (2013-11)

  • Added FirstMassMoment, MomentOfInertia, AngularMomentum.
  • Improved unit numerics.

0.12.1 (2013-07)

  • Typeable Dimensionals.

0.12 (2013-06)

  • Polymorphic _0 (closes issue 39).
  • Added astronomicalUnit.
  • Added imperial volume units.
  • Added ‘mil’ (=inch/1000).
  • Added tau.
  • Added KinematicViscosity.

0.10.1.2 (2011-09)

  • Bumped time dependency to < 1.5.

0.10.1.2 (2011-08)

  • Bumped time dependency to < 1.4.

0.10.1 (2011-08)

GHC 7.2.1 compatibility fix:

  • Increased CGS context-stack to 30.

0.10 (2011-05)

See the announcement.

0.9 (2011-04)

See the announcement.