dimensional-1.6.1: Statically checked physical dimensions

Copyright | Copyright (C) 2006-2018 Bjorn Buckwalter
License | BSD3
Maintainer | bjorn@buckwalter.se
Stability | Stable
Portability | GHC only
Safe Haskell | None
Language | Haskell2010

Numeric.Units.Dimensional.UnitNames

Contents

- Data Types
- Construction of Unit Names
- Standard Names
- Inspecting Prefixes
- Convenience Type Synonyms for Unit Name Transformations
- Forgetting Unwanted Phantom Types

Description

This module provides types and functions for manipulating unit names.

Please note that the details of the name representation may be less stable than the other APIs provided by this package, as new features using them are still being developed.

Synopsis

- data UnitName (m :: Metricality)
- data NameAtom (m :: NameAtomType)
- data Prefix
- type PrefixName = NameAtom 'PrefixAtom
- data Metricality
  - = Metric
  - | NonMetric
- atom :: String -> String -> String -> UnitName 'NonMetric
- applyPrefix :: Prefix -> UnitName 'Metric -> UnitName 'NonMetric
- (*) :: forall (m1 :: Metricality) (m2 :: Metricality). UnitName m1 -> UnitName m2 -> UnitName 'NonMetric
- (/) :: forall (m1 :: Metricality) (m2 :: Metricality). UnitName m1 -> UnitName m2 -> UnitName 'NonMetric
- (^) :: forall (m :: Metricality). UnitName m -> Int -> UnitName 'NonMetric
- product :: Foldable f => f (UnitName 'NonMetric) -> UnitName 'NonMetric
- reduce :: forall (m :: Metricality). UnitName m -> UnitName m
- grouped :: forall (m :: Metricality). UnitName m -> UnitName 'NonMetric
- baseUnitName :: Dimension' -> UnitName 'NonMetric
- siPrefixes :: [Prefix]
- nOne :: UnitName 'NonMetric
- prefixName :: Prefix -> PrefixName
- scaleFactor :: Prefix -> Rational
- type UnitNameTransformer = forall (m :: Metricality). UnitName m -> UnitName 'NonMetric
- type UnitNameTransformer2 = forall (m1 :: Metricality) (m2 :: Metricality). UnitName m1 -> UnitName m2 -> UnitName 'NonMetric
- weaken :: forall (m :: Metricality). UnitName m -> UnitName 'NonMetric
- strengthen :: forall (m :: Metricality). UnitName m -> Maybe (UnitName 'Metric)
- relax :: forall (m1 :: Metricality) (m2 :: Metricality). (Typeable m1, Typeable m2) => UnitName m1 -> Maybe (UnitName m2)
- name_en :: NameAtom m -> String
- abbreviation_en :: NameAtom m -> String
- asAtomic :: forall (m :: Metricality). UnitName m -> Maybe (NameAtom ('UnitAtom m))

# Data Types

data UnitName (m :: Metricality) Source #

The name of a unit.

#### Instances

Instances details

NFData (UnitName m) Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods rnf :: UnitName m -> () Source #
HasInterchangeName (UnitName m) Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods interchangeName :: UnitName m -> InterchangeName Source #
Show (UnitName m) Source # | `UnitName`s are shown with non-breaking spaces.
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods showsPrec :: Int -> UnitName m -> ShowS Source # show :: UnitName m -> String Source # showList :: [UnitName m] -> ShowS Source #
Eq (UnitName m) Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods (==) :: UnitName m -> UnitName m -> Bool Source # (/=) :: UnitName m -> UnitName m -> Bool Source #

data NameAtom (m :: NameAtomType) Source #

Represents the name of an atomic unit or prefix.

#### Instances

Instances details

NFData (NameAtom m) Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods rnf :: NameAtom m -> () Source #
HasInterchangeName (NameAtom m) Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods interchangeName :: NameAtom m -> InterchangeName Source #
Typeable m => Data (NameAtom m) Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NameAtom m -> c (NameAtom m) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NameAtom m) Source #

toConstr :: NameAtom m -> Constr Source #

dataTypeOf :: NameAtom m -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NameAtom m)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NameAtom m)) Source #

gmapT :: (forall b. Data b => b -> b) -> NameAtom m -> NameAtom m Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NameAtom m -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NameAtom m -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> NameAtom m -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> NameAtom m -> u Source #

gmapM :: Monad m0 => (forall d. Data d => d -> m0 d) -> NameAtom m -> m0 (NameAtom m) Source #

gmapMp :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> NameAtom m -> m0 (NameAtom m) Source #

gmapMo :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> NameAtom m -> m0 (NameAtom m) Source #

Generic (NameAtom m) Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

Associated Types

type Rep (NameAtom m) |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

type Rep (NameAtom m) = D1 ('MetaData "NameAtom" "Numeric.Units.Dimensional.UnitNames.Internal" "dimensional-1.6.1-DmNxHObAeML5uhkkhNUdgI" 'False) (C1 ('MetaCons "NameAtom" 'PrefixI 'True) (S1 ('MetaSel ('Just "_interchangeName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 InterchangeName) :*: (S1 ('MetaSel ('Just "abbreviation_en") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "name_en") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))

Methods

from :: NameAtom m -> Rep (NameAtom m) x Source #

to :: Rep (NameAtom m) x -> NameAtom m Source #

Eq (NameAtom m) Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods (==) :: NameAtom m -> NameAtom m -> Bool Source # (/=) :: NameAtom m -> NameAtom m -> Bool Source #
Ord (NameAtom m) Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

Methods

compare :: NameAtom m -> NameAtom m -> Ordering Source #

(<) :: NameAtom m -> NameAtom m -> Bool Source #

(<=) :: NameAtom m -> NameAtom m -> Bool Source #

(>) :: NameAtom m -> NameAtom m -> Bool Source #

(>=) :: NameAtom m -> NameAtom m -> Bool Source #

max :: NameAtom m -> NameAtom m -> NameAtom m Source #

min :: NameAtom m -> NameAtom m -> NameAtom m Source #

type Rep (NameAtom m) Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

type Rep (NameAtom m) = D1 ('MetaData "NameAtom" "Numeric.Units.Dimensional.UnitNames.Internal" "dimensional-1.6.1-DmNxHObAeML5uhkkhNUdgI" 'False) (C1 ('MetaCons "NameAtom" 'PrefixI 'True) (S1 ('MetaSel ('Just "_interchangeName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 InterchangeName) :*: (S1 ('MetaSel ('Just "abbreviation_en") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "name_en") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))

data Prefix Source #

A metric prefix.

#### Instances

Instances details

NFData Prefix Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods rnf :: Prefix -> () Source #
HasInterchangeName Prefix Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods interchangeName :: Prefix -> InterchangeName Source #
Data Prefix Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Prefix -> c Prefix Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Prefix Source #

toConstr :: Prefix -> Constr Source #

dataTypeOf :: Prefix -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Prefix) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Prefix) Source #

gmapT :: (forall b. Data b => b -> b) -> Prefix -> Prefix Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Prefix -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Prefix -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Prefix -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Prefix -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Prefix -> m Prefix Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Prefix -> m Prefix Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Prefix -> m Prefix Source #

Generic Prefix Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

Associated Types

type Rep Prefix |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

type Rep Prefix = D1 ('MetaData "Prefix" "Numeric.Units.Dimensional.UnitNames.Internal" "dimensional-1.6.1-DmNxHObAeML5uhkkhNUdgI" 'False) (C1 ('MetaCons "Prefix" 'PrefixI 'True) (S1 ('MetaSel ('Just "prefixName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PrefixName) :*: S1 ('MetaSel ('Just "scaleFactor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Rational)))

Methods

from :: Prefix -> Rep Prefix x Source #

to :: Rep Prefix x -> Prefix Source #

Eq Prefix Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods (==) :: Prefix -> Prefix -> Bool Source # (/=) :: Prefix -> Prefix -> Bool Source #
Ord Prefix Source # |
Instance details Defined in Numeric.Units.Dimensional.UnitNames.Internal Methods compare :: Prefix -> Prefix -> Ordering Source # (<) :: Prefix -> Prefix -> Bool Source # (<=) :: Prefix -> Prefix -> Bool Source # (>) :: Prefix -> Prefix -> Bool Source # (>=) :: Prefix -> Prefix -> Bool Source # max :: Prefix -> Prefix -> Prefix Source # min :: Prefix -> Prefix -> Prefix Source #
type Rep Prefix Source # |

Instance details

Defined in Numeric.Units.Dimensional.UnitNames.Internal

type Rep Prefix = D1 ('MetaData "Prefix" "Numeric.Units.Dimensional.UnitNames.Internal" "dimensional-1.6.1-DmNxHObAeML5uhkkhNUdgI" 'False) (C1 ('MetaCons "Prefix" 'PrefixI 'True) (S1 ('MetaSel ('Just "prefixName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PrefixName) :*: S1 ('MetaSel ('Just "scaleFactor") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Rational)))

type PrefixName = NameAtom 'PrefixAtom Source #

The name of a metric prefix.

data Metricality Source #

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.

#### Instances

Instances details

NFData Metricality Source # |
Instance details Defined in Numeric.Units.Dimensional.Variants Methods rnf :: Metricality -> () Source #
Data Metricality Source # |

Instance details

Defined in Numeric.Units.Dimensional.Variants

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Metricality -> c Metricality Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Metricality Source #

toConstr :: Metricality -> Constr Source #

dataTypeOf :: Metricality -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Metricality) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Metricality) Source #

gmapT :: (forall b. Data b => b -> b) -> Metricality -> Metricality Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Metricality -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Metricality -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Metricality -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Metricality -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Metricality -> m Metricality Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Metricality -> m Metricality Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Metricality -> m Metricality Source #

Generic Metricality Source # |

Instance details

Defined in Numeric.Units.Dimensional.Variants

Associated Types

type Rep Metricality |
Instance details Defined in Numeric.Units.Dimensional.Variants type Rep Metricality = D1 ('MetaData "Metricality" "Numeric.Units.Dimensional.Variants" "dimensional-1.6.1-DmNxHObAeML5uhkkhNUdgI" 'False) (C1 ('MetaCons "Metric" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NonMetric" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: Metricality -> Rep Metricality x Source #

to :: Rep Metricality x -> Metricality Source #

Eq Metricality Source # |
Instance details Defined in Numeric.Units.Dimensional.Variants Methods (==) :: Metricality -> Metricality -> Bool Source # (/=) :: Metricality -> Metricality -> Bool Source #
Ord Metricality Source # |

Instance details

Defined in Numeric.Units.Dimensional.Variants

Methods

compare :: Metricality -> Metricality -> Ordering Source #

(<) :: Metricality -> Metricality -> Bool Source #

(<=) :: Metricality -> Metricality -> Bool Source #

(>) :: Metricality -> Metricality -> Bool Source #

(>=) :: Metricality -> Metricality -> Bool Source #

max :: Metricality -> Metricality -> Metricality Source #

min :: Metricality -> Metricality -> Metricality Source #

type Rep Metricality Source # |
Instance details Defined in Numeric.Units.Dimensional.Variants type Rep Metricality = D1 ('MetaData "Metricality" "Numeric.Units.Dimensional.Variants" "dimensional-1.6.1-DmNxHObAeML5uhkkhNUdgI" 'False) (C1 ('MetaCons "Metric" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "NonMetric" 'PrefixI 'False) (U1 :: Type -> Type))

# Construction of Unit Names

atom Source #

Arguments

:: String | Interchange name
-> String | Abbreviated name in international English
-> String | Full name in international English
-> UnitName 'NonMetric |

Constructs an atomic name for a custom unit.

applyPrefix :: Prefix -> UnitName 'Metric -> UnitName 'NonMetric Source #

Forms a `UnitName` from a `Metric` name by applying a metric prefix.

(*) :: forall (m1 :: Metricality) (m2 :: Metricality). UnitName m1 -> UnitName m2 -> UnitName 'NonMetric infixl 7 Source #

Form a `UnitName` by taking the product of two others.

(/) :: forall (m1 :: Metricality) (m2 :: Metricality). UnitName m1 -> UnitName m2 -> UnitName 'NonMetric infixl 7 Source #

Form a `UnitName` by dividing one by another.

(^) :: forall (m :: Metricality). UnitName m -> Int -> UnitName 'NonMetric infixr 8 Source #

Form a `UnitName` by raising a name to an integer power.

product :: Foldable f => f (UnitName 'NonMetric) -> UnitName 'NonMetric Source #

Forms the product of a list of `UnitName`s.

If you wish to form a heterogenous product of `Metric` and `NonMetric` units you should apply `weaken` to the `Metric` ones.

reduce :: forall (m :: Metricality). UnitName m -> UnitName m Source #

Reduce a `UnitName` by algebraic simplifications.

grouped :: forall (m :: Metricality). UnitName m -> UnitName 'NonMetric Source #

Constructs a `UnitName` by applying a grouping operation to another `UnitName`, which may be useful to express precedence.

# Standard Names

baseUnitName :: Dimension' -> UnitName 'NonMetric Source #

The name of the base unit associated with a specified dimension.

siPrefixes :: [Prefix] Source #

A list of all `Prefix`es defined by the SI.

nOne :: UnitName 'NonMetric Source #

The name of the unit of dimensionless values.

# Inspecting Prefixes

prefixName :: Prefix -> PrefixName Source #

The name of a metric prefix.

scaleFactor :: Prefix -> Rational Source #

The scale factor denoted by a metric prefix.

# Convenience Type Synonyms for Unit Name Transformations

type UnitNameTransformer = forall (m :: Metricality). UnitName m -> UnitName 'NonMetric Source #

The type of a unit name transformation that may be associated with an operation that takes a single unit as input.

type UnitNameTransformer2 = forall (m1 :: Metricality) (m2 :: Metricality). UnitName m1 -> UnitName m2 -> UnitName 'NonMetric Source #

The type of a unit name transformation that may be associated with an operation that takes two units as input.

# Forgetting Unwanted Phantom Types

weaken :: forall (m :: Metricality). UnitName m -> UnitName 'NonMetric Source #

Convert a `UnitName` which may or may not be `Metric` to one which is certainly `NonMetric`.

strengthen :: forall (m :: Metricality). UnitName m -> Maybe (UnitName 'Metric) Source #

Attempt to convert a `UnitName` which may or may not be `Metric` to one which is certainly `Metric`.

relax :: forall (m1 :: Metricality) (m2 :: Metricality). (Typeable m1, Typeable m2) => UnitName m1 -> Maybe (UnitName m2) Source #

Convert a `UnitName` of one `Metricality` into a name of another metricality by strengthening or weakening if neccessary. Because it may not be possible to strengthen, the result is returned in a `Maybe` wrapper.

name_en :: NameAtom m -> String Source #

The full name of the unit in international English.

abbreviation_en :: NameAtom m -> String Source #

The abbreviated name of the unit in international English.

asAtomic :: forall (m :: Metricality). UnitName m -> Maybe (NameAtom ('UnitAtom m)) Source #

Converts a `UnitName` to a `NameAtom`, if possible.