dimensional-1.5: Statically checked physical dimensions

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

Numeric.Units.Dimensional.Dynamic

Contents

- Dynamic Quantities
- Dynamic Units
  - Arithmetic on Dynamic Units

Description

Defines types for manipulation of units and quantities without phantom types for their dimensions.

Synopsis

- data AnyQuantity a
- data DynQuantity a
- class Demotable (q :: Type -> Type)
- class Promotable (q :: Type -> Type)
- class HasDynamicDimension a where
  - dynamicDimension :: a -> DynamicDimension
- data DynamicDimension
  - = NoDimension
  - | SomeDimension Dimension'
  - | AnyDimension
- promoteQuantity :: forall a d q. (Promotable q, KnownDimension d) => q a -> Maybe (Quantity d a)
- demoteQuantity :: (Demotable q, Promotable d) => q a -> d a
- (*~) :: (Floating a, Promotable q) => a -> AnyUnit -> q a
- (/~) :: (Floating a, Promotable q) => q a -> AnyUnit -> Maybe a
- invalidQuantity :: DynQuantity a
- polydimensionalZero :: Num a => DynQuantity a
- data AnyUnit
- demoteUnit :: forall m d a. KnownDimension d => Unit m d a -> AnyUnit
- promoteUnit :: forall d. KnownDimension d => AnyUnit -> Maybe (Unit 'NonMetric d ExactPi)
- demoteUnit' :: KnownDimension d => Unit m d ExactPi -> AnyUnit
- siUnit :: Dimension' -> AnyUnit
- anyUnitName :: AnyUnit -> UnitName 'NonMetric
- (*) :: AnyUnit -> AnyUnit -> AnyUnit
- (/) :: AnyUnit -> AnyUnit -> AnyUnit
- (^) :: Integral a => AnyUnit -> a -> AnyUnit
- recip :: AnyUnit -> AnyUnit
- applyPrefix :: Prefix -> AnyUnit -> Maybe AnyUnit

# Dynamic Quantities

data AnyQuantity a Source #

A `Quantity` whose `Dimension` is only known dynamically.

#### Instances

Instances details

Demotable AnyQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods demotableOut :: AnyQuantity a -> AnyQuantity a
Promotable AnyQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods promotableIn :: AnyQuantity a -> AnyQuantity a promotableOut :: AnyQuantity a -> DynQuantity a
Generic1 AnyQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Associated Types type Rep1 AnyQuantity :: k -> Type Source # Methods from1 :: forall (a :: k). AnyQuantity a -> Rep1 AnyQuantity a Source # to1 :: forall (a :: k). Rep1 AnyQuantity a -> AnyQuantity a Source #
Data a => Data (AnyQuantity a) Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

Methods

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

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

toConstr :: AnyQuantity a -> Constr Source #

dataTypeOf :: AnyQuantity a -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Num a => Monoid (AnyQuantity a) Source # | `AnyQuantity`s form a `Monoid` under multiplication, but not under addition because they may not be added together if their dimensions do not match.
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods mempty :: AnyQuantity a Source # mappend :: AnyQuantity a -> AnyQuantity a -> AnyQuantity a Source # mconcat :: [AnyQuantity a] -> AnyQuantity a Source #
Num a => Semigroup (AnyQuantity a) Source # | `AnyQuantity`s form a `Semigroup` under multiplication, but not under addition because they may not be added together if their dimensions do not match.
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods (<>) :: AnyQuantity a -> AnyQuantity a -> AnyQuantity a Source # sconcat :: NonEmpty (AnyQuantity a) -> AnyQuantity a Source # stimes :: Integral b => b -> AnyQuantity a -> AnyQuantity a Source #
Generic (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Associated Types type Rep (AnyQuantity a) :: Type -> Type Source # Methods from :: AnyQuantity a -> Rep (AnyQuantity a) x Source # to :: Rep (AnyQuantity a) x -> AnyQuantity a Source #
Show a => Show (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods showsPrec :: Int -> AnyQuantity a -> ShowS Source # show :: AnyQuantity a -> String Source # showList :: [AnyQuantity a] -> ShowS Source #
NFData a => NFData (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods rnf :: AnyQuantity a -> () Source #
HasDimension (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dimension :: AnyQuantity a -> Dimension' Source #
HasDynamicDimension (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: AnyQuantity a -> DynamicDimension Source #
Eq a => Eq (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods (==) :: AnyQuantity a -> AnyQuantity a -> Bool Source # (/=) :: AnyQuantity a -> AnyQuantity a -> Bool Source #
type Rep1 AnyQuantity Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

type Rep1 AnyQuantity = D1 ('MetaData "AnyQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.5-Jh8KVMZ2g1X80m3wFNP7DL" 'False) (C1 ('MetaCons "AnyQuantity" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Dimension') :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))

type Rep (AnyQuantity a) Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

type Rep (AnyQuantity a) = D1 ('MetaData "AnyQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.5-Jh8KVMZ2g1X80m3wFNP7DL" 'False) (C1 ('MetaCons "AnyQuantity" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Dimension') :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))

data DynQuantity a Source #

Possibly a `Quantity` whose `Dimension` is only known dynamically.

By modeling the absence of a value, this type differs from `AnyQuantity` in that it may not be a `Quantity` of any `Dimension` whatsoever, but in exchange it gains instances for the common numeric classes. It's therefore useful for manipulating, and not merely storing, quantities of unknown dimension.

This type also contains a `polydimensionalZero`, representing zero value of any dimension.

Note that the `Eq` instance for `DynQuantity` equates all representations of an invalid value, and also does not equate polydimensional zero with zero of any specific dimension.

#### Instances

Instances details

Promotable DynQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods promotableIn :: AnyQuantity a -> DynQuantity a promotableOut :: DynQuantity a -> DynQuantity a
Generic1 DynQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Associated Types type Rep1 DynQuantity :: k -> Type Source # Methods from1 :: forall (a :: k). DynQuantity a -> Rep1 DynQuantity a Source # to1 :: forall (a :: k). Rep1 DynQuantity a -> DynQuantity a Source #
Data a => Data (DynQuantity a) Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

Methods

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

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

toConstr :: DynQuantity a -> Constr Source #

dataTypeOf :: DynQuantity a -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Num a => Monoid (DynQuantity a) Source # | `DynQuantity`s form a `Monoid` under multiplication, but not under addition because they may not be added together if their dimensions do not match.
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods mempty :: DynQuantity a Source # mappend :: DynQuantity a -> DynQuantity a -> DynQuantity a Source # mconcat :: [DynQuantity a] -> DynQuantity a Source #
Num a => Semigroup (DynQuantity a) Source # | `DynQuantity`s form a `Semigroup` under multiplication, but not under addition because they may not be added together if their dimensions do not match.
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods (<>) :: DynQuantity a -> DynQuantity a -> DynQuantity a Source # sconcat :: NonEmpty (DynQuantity a) -> DynQuantity a Source # stimes :: Integral b => b -> DynQuantity a -> DynQuantity a Source #
Floating a => Floating (DynQuantity a) Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

Methods

pi :: DynQuantity a Source #

exp :: DynQuantity a -> DynQuantity a Source #

log :: DynQuantity a -> DynQuantity a Source #

sqrt :: DynQuantity a -> DynQuantity a Source #

(**) :: DynQuantity a -> DynQuantity a -> DynQuantity a Source #

logBase :: DynQuantity a -> DynQuantity a -> DynQuantity a Source #

sin :: DynQuantity a -> DynQuantity a Source #

cos :: DynQuantity a -> DynQuantity a Source #

tan :: DynQuantity a -> DynQuantity a Source #

asin :: DynQuantity a -> DynQuantity a Source #

acos :: DynQuantity a -> DynQuantity a Source #

atan :: DynQuantity a -> DynQuantity a Source #

sinh :: DynQuantity a -> DynQuantity a Source #

cosh :: DynQuantity a -> DynQuantity a Source #

tanh :: DynQuantity a -> DynQuantity a Source #

asinh :: DynQuantity a -> DynQuantity a Source #

acosh :: DynQuantity a -> DynQuantity a Source #

atanh :: DynQuantity a -> DynQuantity a Source #

log1p :: DynQuantity a -> DynQuantity a Source #

expm1 :: DynQuantity a -> DynQuantity a Source #

log1pexp :: DynQuantity a -> DynQuantity a Source #

log1mexp :: DynQuantity a -> DynQuantity a Source #

Generic (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Associated Types type Rep (DynQuantity a) :: Type -> Type Source # Methods from :: DynQuantity a -> Rep (DynQuantity a) x Source # to :: Rep (DynQuantity a) x -> DynQuantity a Source #
Num a => Num (DynQuantity a) Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

Methods

(+) :: DynQuantity a -> DynQuantity a -> DynQuantity a Source #

(-) :: DynQuantity a -> DynQuantity a -> DynQuantity a Source #

(*) :: DynQuantity a -> DynQuantity a -> DynQuantity a Source #

negate :: DynQuantity a -> DynQuantity a Source #

abs :: DynQuantity a -> DynQuantity a Source #

signum :: DynQuantity a -> DynQuantity a Source #

fromInteger :: Integer -> DynQuantity a Source #

Fractional a => Fractional (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods (/) :: DynQuantity a -> DynQuantity a -> DynQuantity a Source # recip :: DynQuantity a -> DynQuantity a Source # fromRational :: Rational -> DynQuantity a Source #
Show a => Show (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods showsPrec :: Int -> DynQuantity a -> ShowS Source # show :: DynQuantity a -> String Source # showList :: [DynQuantity a] -> ShowS Source #
NFData a => NFData (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods rnf :: DynQuantity a -> () Source #
HasDynamicDimension (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: DynQuantity a -> DynamicDimension Source #
Eq a => Eq (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods (==) :: DynQuantity a -> DynQuantity a -> Bool Source # (/=) :: DynQuantity a -> DynQuantity a -> Bool Source #
type Rep1 DynQuantity Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

type Rep1 DynQuantity = D1 ('MetaData "DynQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.5-Jh8KVMZ2g1X80m3wFNP7DL" 'False) (C1 ('MetaCons "DynQuantity" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DynamicDimension) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))

type Rep (DynQuantity a) Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

type Rep (DynQuantity a) = D1 ('MetaData "DynQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.5-Jh8KVMZ2g1X80m3wFNP7DL" 'False) (C1 ('MetaCons "DynQuantity" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DynamicDimension) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

class Demotable (q :: Type -> Type) Source #

The class of types that can be used to model `Quantity`s that are certain to have a value with some dimension.

Minimal complete definition

demotableOut

#### Instances

Instances details

Demotable AnyQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods demotableOut :: AnyQuantity a -> AnyQuantity a
KnownDimension d => Demotable (Quantity d) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods demotableOut :: Quantity d a -> AnyQuantity a

class Promotable (q :: Type -> Type) Source #

The class of types that can be used to model `Quantity`s whose `Dimension`s are only known dynamically.

Minimal complete definition

promotableIn, promotableOut

#### Instances

Instances details

Promotable AnyQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods promotableIn :: AnyQuantity a -> AnyQuantity a promotableOut :: AnyQuantity a -> DynQuantity a
Promotable DynQuantity Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods promotableIn :: AnyQuantity a -> DynQuantity a promotableOut :: DynQuantity a -> DynQuantity a

class HasDynamicDimension a where Source #

Dimensional values, or those that are only possibly dimensional, inhabit this class, which allows access to a term-level representation of their dimension.

Minimal complete definition

Nothing

Methods

dynamicDimension :: a -> DynamicDimension Source #

Gets the `DynamicDimension` of a dynamic dimensional value, which may be `NoDimension` if it does not represent a dimensional value of any `Dimension`.

A default implementation is available for types that are also in the `HasDimension` typeclass.

default dynamicDimension :: HasDimension a => a -> DynamicDimension Source #

#### Instances

Instances details

HasDynamicDimension Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dynamicDimension :: Dimension' -> DynamicDimension Source #
HasDynamicDimension DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dynamicDimension :: DynamicDimension -> DynamicDimension Source #
HasDynamicDimension AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: AnyUnit -> DynamicDimension Source #
HasDynamicDimension (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: AnyQuantity a -> DynamicDimension Source #
HasDynamicDimension (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: DynQuantity a -> DynamicDimension Source #
(KnownTypeInt l, KnownTypeInt m, KnownTypeInt t, KnownTypeInt i, KnownTypeInt th, KnownTypeInt n, KnownTypeInt j) => HasDynamicDimension (Proxy ('Dim l m t i th n j)) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TypeLevel Methods dynamicDimension :: Proxy ('Dim l m t i th n j) -> DynamicDimension Source #
KnownDimension d => HasDynamicDimension (Dimensional v d a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Internal Methods dynamicDimension :: Dimensional v d a -> DynamicDimension Source #

data DynamicDimension Source #

The dimension of a dynamic value, which may not have any dimension at all.

Constructors

NoDimension | The value has no valid dimension.
SomeDimension Dimension' | The value has the given dimension.
AnyDimension | The value may be interpreted as having any dimension.

#### Instances

Instances details

Data DynamicDimension Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dimensions.TermLevel

Methods

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

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

toConstr :: DynamicDimension -> Constr Source #

dataTypeOf :: DynamicDimension -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Generic DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Associated Types type Rep DynamicDimension :: Type -> Type Source # Methods from :: DynamicDimension -> Rep DynamicDimension x Source # to :: Rep DynamicDimension x -> DynamicDimension Source #
Show DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods showsPrec :: Int -> DynamicDimension -> ShowS Source # show :: DynamicDimension -> String Source # showList :: [DynamicDimension] -> ShowS Source #
NFData DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods rnf :: DynamicDimension -> () Source #
HasDynamicDimension DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dynamicDimension :: DynamicDimension -> DynamicDimension Source #
Eq DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods (==) :: DynamicDimension -> DynamicDimension -> Bool Source # (/=) :: DynamicDimension -> DynamicDimension -> Bool Source #
Ord DynamicDimension Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dimensions.TermLevel

Methods

compare :: DynamicDimension -> DynamicDimension -> Ordering Source #

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

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

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

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

max :: DynamicDimension -> DynamicDimension -> DynamicDimension Source #

min :: DynamicDimension -> DynamicDimension -> DynamicDimension Source #

type Rep DynamicDimension Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dimensions.TermLevel

type Rep DynamicDimension = D1 ('MetaData "DynamicDimension" "Numeric.Units.Dimensional.Dimensions.TermLevel" "dimensional-1.5-Jh8KVMZ2g1X80m3wFNP7DL" 'False) (C1 ('MetaCons "NoDimension" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "SomeDimension" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Dimension')) :+: C1 ('MetaCons "AnyDimension" 'PrefixI 'False) (U1 :: Type -> Type)))

promoteQuantity :: forall a d q. (Promotable q, KnownDimension d) => q a -> Maybe (Quantity d a) Source #

Converts a dynamic quantity such as an `AnyQuantity` or a `DynQuantity` into a `Quantity`, or to `Nothing` if the dynamic quantity cannot be represented in the narrower result type.

demoteQuantity :: (Demotable q, Promotable d) => q a -> d a Source #

Forgets information about a `Quantity` or `AnyQuantity`, yielding an `AnyQuantity` or a `DynQuantity`.

(*~) :: (Floating a, Promotable q) => a -> AnyUnit -> q a Source #

Forms a dynamic quantity by multipliying a number and a dynamic unit.

(/~) :: (Floating a, Promotable q) => q a -> AnyUnit -> Maybe a Source #

Divides a dynamic quantity by a dynamic unit, obtaining the numerical value of the quantity expressed in that unit if they are of the same physical dimension, or `Nothing` otherwise.

invalidQuantity :: DynQuantity a Source #

A `DynQuantity` which does not correspond to a value of any dimension.

polydimensionalZero :: Num a => DynQuantity a Source #

A `DynQuantity` which corresponds to zero value of any dimension.

When combined through arithmetic with other `DynQuantity`s, inference is performed. For example, adding a length to polydimensional zero produces that length. Adding two polydimensional zeros produces another. Taking the sine of a polydimensional zero interprets it as a dimensionless zero and produces a dimensionless result.

Note that division by `polydimensionalZero` produces a polydimensional result, which may be an error or some representation of infinity, as determined by the underlying arithmetic type. This behavior was chosen for consistency with the behavior of division by zero `DynQuantity`s of a specific dimension.

# Dynamic Units

data AnyUnit Source #

A `Unit` whose `Dimension` is only known dynamically.

#### Instances

Instances details

Monoid AnyUnit Source # | `AnyUnit`s form a `Monoid` under multiplication.
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods mempty :: AnyUnit Source # mappend :: AnyUnit -> AnyUnit -> AnyUnit Source # mconcat :: [AnyUnit] -> AnyUnit Source #
Semigroup AnyUnit Source # | `AnyUnit`s form a `Semigroup` under multiplication.
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods (<>) :: AnyUnit -> AnyUnit -> AnyUnit Source # sconcat :: NonEmpty AnyUnit -> AnyUnit Source # stimes :: Integral b => b -> AnyUnit -> AnyUnit Source #
Generic AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Associated Types type Rep AnyUnit :: Type -> Type Source # Methods from :: AnyUnit -> Rep AnyUnit x Source # to :: Rep AnyUnit x -> AnyUnit Source #
Show AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods showsPrec :: Int -> AnyUnit -> ShowS Source # show :: AnyUnit -> String Source # showList :: [AnyUnit] -> ShowS Source #
HasDimension AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dimension :: AnyUnit -> Dimension' Source #
HasDynamicDimension AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: AnyUnit -> DynamicDimension Source #
HasInterchangeName AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods interchangeName :: AnyUnit -> InterchangeName Source #
type Rep AnyUnit Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dynamic

type Rep AnyUnit = D1 ('MetaData "AnyUnit" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.5-Jh8KVMZ2g1X80m3wFNP7DL" 'False) (C1 ('MetaCons "AnyUnit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Dimension') :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (UnitName 'NonMetric)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ExactPi))))

demoteUnit :: forall m d a. KnownDimension d => Unit m d a -> AnyUnit Source #

Converts a `Unit` of statically known `Dimension` into an `AnyUnit`.

promoteUnit :: forall d. KnownDimension d => AnyUnit -> Maybe (Unit 'NonMetric d ExactPi) Source #

Converts an `AnyUnit` into a `Unit` of statically known `Dimension`, or `Nothing` if the dimension does not match.

The result is represented in `ExactPi`, conversion to other representations is possible using `changeRepApproximate`.

The result is always tagged as `NonMetric`, conversion to a `Metric` unit can be attempted using `strengthen`.

demoteUnit' :: KnownDimension d => Unit m d ExactPi -> AnyUnit Source #

Converts a `Unit` of statically known `Dimension` into an `AnyUnit`.

This is the same as the more general `demoteUnit` but is useful in certain circumstances to avoid needlessly introducing an ambiguous type variable.

siUnit :: Dimension' -> AnyUnit Source #

The dynamic SI coherent unit of a given dimension.

anyUnitName :: AnyUnit -> UnitName 'NonMetric Source #

Extracts the `UnitName` of an `AnyUnit`.

## Arithmetic on Dynamic Units

(*) :: AnyUnit -> AnyUnit -> AnyUnit Source #

Forms the product of two dynamic units.

(/) :: AnyUnit -> AnyUnit -> AnyUnit Source #

Forms the quotient of two dynamic units.

(^) :: Integral a => AnyUnit -> a -> AnyUnit Source #

Raises a dynamic unit to an integer power.

recip :: AnyUnit -> AnyUnit Source #

Forms the reciprocal of a dynamic unit.

applyPrefix :: Prefix -> AnyUnit -> Maybe AnyUnit Source #

Applies a prefix to a dynamic unit. Returns `Nothing` if the `Unit` was `NonMetric` and thus could not accept a prefix.