The dimensional package

[Tags: bsd3, library]

Dimensional is a library providing data types for performing arithmetic with physical quantities and units. Information about the physical dimensions of the quantities and units is embedded in their types and the validity of operations is verified by the type checker at compile time. The boxing and unboxing of numerical values as quantities is done by multiplication and division with units. The library is designed to, as far as is practical, enforce/encourage best practices of unit usage. Version 1 of the dimensional package differs from earlier version in that the dimension tracking is implemented using Closed Type Families and Data Kinds rather than functional dependencies. This enables a number of features, including improved support for unit names and quantities with statically-unknown dimensions. Requires GHC 7.8 or later.

[Skip to ReadMe]


Versions0.7, 0.7.1, 0.7.2, 0.7.3, 0.8,,, 0.9, 0.10, 0.10.1,,, 0.10.2, 0.12, 0.12.1,, 0.12.2, 0.12.3, 0.13,,,,
Dependenciesbase (>=4.7 && <5), deepseq (>=1.3), exact-pi (>= && <0.5), numtype-dk (>=0.5 && <1.1), vector (>=0.10) [details]
CopyrightBjorn Buckwalter 2006-2015
AuthorBjorn Buckwalter
CategoryMath, Physics
Home page
Source repositoryhead: git clone
UploadedTue Nov 24 14:17:12 UTC 2015 by dmcclean
DistributionsDebian:, LTSHaskell:, NixOS:, Stackage:
Downloads4279 total (131 in last 30 days)
3 []
StatusDocs available [build log]
Last success reported on 2015-11-24 [all 2 reports]




Maintainers' corner

For package maintainers and hackage trustees

Readme for 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


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


For project information (issues, updates, wiki, examples) see: