HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduledimensional-1.6.2Haskell2010

Numeric.Units.Dimensional.FixedPoint

Defines types for manipulation of quantities with fixed point representations.

Contents
  1. Types
  2. Physical Dimensions
  3. Dimension Arithmetic
  4. Term Level Representation of Dimensions
  5. Dimensional Arithmetic
  6. Transcendental Functions
  7. Via Double
  8. Via arbitary Floating type
  9. Operations on Collections
  10. Conversion Between Representations
  11. Dimension Synonyms
  12. Quantity Synonyms
  13. Constants
  14. Constructing Units
  15. Unit Metadata
  16. Commonly Used Type Synonyms
Synopsis
  • Packagedimensional-1.6.2
  • Exports108
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFixedPoint.hs

Types

We provide access to the same Dimensional, Unit, and Quantity types as are exposed by Numeric.Units.Dimensional, but additionally offer the SQuantity type to represent scaled quantities. Fixed-point quantities are quantities backed by integers, it is frequently necessary to scale those integers into a range appropriate for the physical problem at hand.

familydata family Dimensional (v :: Variant) :: Dimension -> Type -> Type

A dimensional value, either a Quantity or a Unit, parameterized by its Dimension and representation.

Instances34Generic1, Demotable, Functor, Eq1, Ord1, NFData, …
typetype SQuantity (s :: ExactPi') = Dimensional ('DQuantity s)

A dimensional quantity, stored as an ExactPi' multiple of its value in its dimension's SI coherent unit.

The name is an abbreviation for scaled quantity.

datadata Metricality

Encodes whether a unit is a metric unit, that is, whether it can be combined with a metric prefix to form a related unit.

Constructors

  • Metric

    Capable of receiving a metric prefix.

  • NonMetric

    Incapable of receiving a metric prefix.

Instances6Eq, Data, Ord, Generic, NFData, Rep

Physical Dimensions

datadata Dimension

Represents a physical dimension in the basis of the 7 SI base dimensions, where the respective dimensions are represented by type variables using the following convention:

  • l: Length

  • m: Mass

  • t: Time

  • i: Electric current

  • th: Thermodynamic temperature

  • n: Amount of substance

  • j: Luminous intensity

For the equivalent term-level representation, see Dimension'

Instances2HasDimension, HasDynamicDimension

Dimension Arithmetic

familytype family (*) (a :: Dimension) (b :: Dimension) :: Dimension where

Multiplication of dimensions corresponds to addition of the base dimensions' exponents.

Equations

  • (*) DOne d = d
  • (*) d DOne = d
  • (*) ('Dim l m t i th n j) ('Dim l' m' t' i' th' n' j') = 'Dim (l + l') (m + m') (t + t') (i + i') (th + th') (n + n') (j + j')
familytype family (/) (a :: Dimension) (d :: Dimension) :: Dimension where

Division of dimensions corresponds to subtraction of the base dimensions' exponents.

Equations

  • (/) d DOne = d
  • (/) d d = DOne
  • (/) ('Dim l m t i th n j) ('Dim l' m' t' i' th' n' j') = 'Dim (l - l') (m - m') (t - t') (i - i') (th - th') (n - n') (j - j')
familytype family (^) (d :: Dimension) (x :: TypeInt) :: Dimension where

Powers of dimensions correspond to multiplication of the base dimensions' exponents by the exponent.

We limit ourselves to integer powers of Dimensionals as fractional powers make little physical sense.

Equations

typetype Recip (d :: Dimension) = DOne / d

The reciprocal of a dimension is defined as the result of dividing DOne by it, or of negating each of the base dimensions' exponents.

Term Level Representation of Dimensions

datadata Dimension'

A physical dimension, encoded as 7 integers, representing a factorization of the dimension into the 7 SI base dimensions. By convention they are stored in the same order as in the Dimension data kind.

Constructors

Instances11Eq, Data, Ord, Show, Generic, Semigroup, …
classclass HasDynamicDimension a => HasDimension a where

Dimensional values inhabit this class, which allows access to a term-level representation of their dimension.

Methods

Instances5HasDimension

Dimensional Arithmetic

Transcendental Functions

Via Double

Via arbitary Floating type

Operations on Collections

Conversion Between Representations

classclass KnownVariant (v :: Variant) where

A KnownVariant is one whose term-level Dimensional values we can represent with an associated data family instance and manipulate with certain functions, not all of which are exported from the package.

Each validly constructed type of kind Variant has a KnownVariant instance.

Methods

  • dmap :: (a1 -> a2) -> Dimensional v d a1 -> Dimensional v d a2

    Maps over the underlying representation of a dimensional value. The caller is responsible for ensuring that the supplied function respects the dimensional abstraction. This means that the function must preserve numerical values, or linearly scale them while preserving the origin.

Instances2KnownVariant

Dimension Synonyms

Quantity Synonyms

Constants

Note that, other than _0 and epsilon, these constants may not be exactly representable with certain scale factors.

Constructing Units

valueone :: Num a => Unit 'NonMetric DOne a

The unit one has dimension DOne and is the base unit of dimensionless values.

As detailed in 7.10 "Values of quantities expressed simply as numbers: the unit one, symbol 1" of [1], the unit one generally does not appear in expressions. However, for us it is necessary to use one as we would any other unit to perform the "wrapping" of dimensionless values.

valuemkUnitR :: Floating a => UnitName m -> ExactPi -> Unit m1 d a -> Unit m d a

Forms a new atomic Unit by specifying its UnitName and its definition as a multiple of another Unit.

Use this variant when the scale factor of the resulting unit is irrational or Approximate. See mkUnitQ for when it is rational and mkUnitZ for when it is an integer.

Note that supplying zero as a definining quantity is invalid, as the library relies upon units forming a group under multiplication.

Supplying negative defining quantities is allowed and handled gracefully, but is discouraged on the grounds that it may be unexpected by other readers.

Unit Metadata

valueexactValue :: Unit m d a -> ExactPi

Extracts the exact value of a Unit, expressed in terms of the SI coherent derived unit (see siUnit) of the same Dimension.

Note that the actual value may in some cases be approximate, for example if the unit is defined by experiment.

Commonly Used Type Synonyms

These type synonyms for commonly used fixed-point types are provided for convenience.