HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduledimensional-1.5Haskell2010

Numeric.Units.Dimensional.FixedPoint

Defines types for manipulation of quantities with fixed point representations.

  • 29 types
  • 2 classes
  • 72 values
  • Packagedimensional-1.5
  • Exports108
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFixedPoint.hs

Types

5 declarations

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

1 declaration
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

8 declarations

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

8 declarations

Quantity Synonyms

8 declarations

Constants

13 declarations
valueepsilon :: Integral a => SQuantity s d a
#

The smallest positive representable value in a given fixed-point scaled quantity type.

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

Constructing Units

5 declarations
valuesiUnit :: (KnownDimension d, Num a) => Unit 'NonMetric d a
#

A polymorphic Unit which can be used in place of the coherent SI base unit of any dimension. This allows polymorphic quantity creation and destruction without exposing the Dimensional constructor.

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.

valuemkUnitZ :: Num a => UnitName m -> Integer -> 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 an integer. See mkUnitQ for when it is rational and mkUnitR for the general case.

For more information see mkUnitR.

Unit Metadata

5 declarations
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

5 declarations

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

typetype Q (n :: Natural) a = SQuantity (QScale n) DOne a
#

A dimensionless number with n fractional bits, using a representation of type a.