dimensional-1.3: Statically checked physical dimensions, using Type Families and Data Kinds.

Numeric.Units.Dimensional.Dynamic

Description

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

Synopsis

# Dynamic Quantities

data AnyQuantity a Source #

A Quantity whose Dimension is only known dynamically.

Instances
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Eq a => Eq (AnyQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods(==) :: AnyQuantity a -> AnyQuantity a -> Bool #(/=) :: AnyQuantity a -> AnyQuantity a -> Bool # Data a => Data (AnyQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AnyQuantity a -> c (AnyQuantity a) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (AnyQuantity a) #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (AnyQuantity a)) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (AnyQuantity a)) #gmapT :: (forall b. Data b => b -> b) -> AnyQuantity a -> AnyQuantity a #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AnyQuantity a -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AnyQuantity a -> r #gmapQ :: (forall d. Data d => d -> u) -> AnyQuantity a -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> AnyQuantity a -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> AnyQuantity a -> m (AnyQuantity a) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AnyQuantity a -> m (AnyQuantity a) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AnyQuantity a -> m (AnyQuantity a) # Show a => Show (AnyQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic MethodsshowsPrec :: Int -> AnyQuantity a -> ShowS #show :: AnyQuantity a -> String #showList :: [AnyQuantity a] -> ShowS # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Associated Typestype Rep (AnyQuantity a) :: Type -> Type # Methodsfrom :: AnyQuantity a -> Rep (AnyQuantity a) x #to :: Rep (AnyQuantity a) x -> AnyQuantity a # Num a => Semigroup (AnyQuantity a) Source # AnyQuantitys form a Semigroup under multiplication, but not under addition because they may not be added together if their dimensions do not match. Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods(<>) :: AnyQuantity a -> AnyQuantity a -> AnyQuantity a #stimes :: Integral b => b -> AnyQuantity a -> AnyQuantity a # Num a => Monoid (AnyQuantity a) Source # AnyQuantitys form a Monoid under multiplication, but not under addition because they may not be added together if their dimensions do not match. Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsmappend :: AnyQuantity a -> AnyQuantity a -> AnyQuantity a #mconcat :: [AnyQuantity a] -> AnyQuantity a # NFData a => NFData (AnyQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsrnf :: AnyQuantity a -> () # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Associated Typestype Rep1 AnyQuantity :: k -> Type # Methods type Rep (AnyQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic type Rep (AnyQuantity a) = D1 (MetaData "AnyQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" 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))) type Rep1 AnyQuantity Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic type Rep1 AnyQuantity = D1 (MetaData "AnyQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" 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))

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
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Eq a => Eq (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods(==) :: DynQuantity a -> DynQuantity a -> Bool #(/=) :: DynQuantity a -> DynQuantity a -> Bool # Floating a => Floating (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsexp :: DynQuantity a -> DynQuantity a #log :: DynQuantity a -> DynQuantity a #sqrt :: DynQuantity a -> DynQuantity a #(**) :: DynQuantity a -> DynQuantity a -> DynQuantity a #logBase :: DynQuantity a -> DynQuantity a -> DynQuantity a #sin :: DynQuantity a -> DynQuantity a #cos :: DynQuantity a -> DynQuantity a #tan :: DynQuantity a -> DynQuantity a #asin :: DynQuantity a -> DynQuantity a #acos :: DynQuantity a -> DynQuantity a #atan :: DynQuantity a -> DynQuantity a #sinh :: DynQuantity a -> DynQuantity a #cosh :: DynQuantity a -> DynQuantity a #tanh :: DynQuantity a -> DynQuantity a #asinh :: DynQuantity a -> DynQuantity a #acosh :: DynQuantity a -> DynQuantity a #atanh :: DynQuantity a -> DynQuantity a #log1p :: DynQuantity a -> DynQuantity a #expm1 :: DynQuantity a -> DynQuantity a # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods(/) :: DynQuantity a -> DynQuantity a -> DynQuantity a #recip :: DynQuantity a -> DynQuantity a # Data a => Data (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DynQuantity a -> c (DynQuantity a) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (DynQuantity a) #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (DynQuantity a)) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (DynQuantity a)) #gmapT :: (forall b. Data b => b -> b) -> DynQuantity a -> DynQuantity a #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DynQuantity a -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DynQuantity a -> r #gmapQ :: (forall d. Data d => d -> u) -> DynQuantity a -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> DynQuantity a -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> DynQuantity a -> m (DynQuantity a) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DynQuantity a -> m (DynQuantity a) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DynQuantity a -> m (DynQuantity a) # Num a => Num (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods(+) :: DynQuantity a -> DynQuantity a -> DynQuantity a #(-) :: DynQuantity a -> DynQuantity a -> DynQuantity a #(*) :: DynQuantity a -> DynQuantity a -> DynQuantity a #abs :: DynQuantity a -> DynQuantity a # Show a => Show (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic MethodsshowsPrec :: Int -> DynQuantity a -> ShowS #show :: DynQuantity a -> String #showList :: [DynQuantity a] -> ShowS # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Associated Typestype Rep (DynQuantity a) :: Type -> Type # Methodsfrom :: DynQuantity a -> Rep (DynQuantity a) x #to :: Rep (DynQuantity a) x -> DynQuantity a # Num a => Semigroup (DynQuantity a) Source # DynQuantitys form a Semigroup under multiplication, but not under addition because they may not be added together if their dimensions do not match. Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods(<>) :: DynQuantity a -> DynQuantity a -> DynQuantity a #stimes :: Integral b => b -> DynQuantity a -> DynQuantity a # Num a => Monoid (DynQuantity a) Source # DynQuantitys form a Monoid under multiplication, but not under addition because they may not be added together if their dimensions do not match. Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsmappend :: DynQuantity a -> DynQuantity a -> DynQuantity a #mconcat :: [DynQuantity a] -> DynQuantity a # NFData a => NFData (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsrnf :: DynQuantity a -> () # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Associated Typestype Rep1 DynQuantity :: k -> Type # Methods type Rep (DynQuantity a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic type Rep (DynQuantity a) = D1 (MetaData "DynQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" 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))) type Rep1 DynQuantity Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic type Rep1 DynQuantity = D1 (MetaData "DynQuantity" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" 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))

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

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

Minimal complete definition

demotableOut

Instances
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic MethodsdemotableOut :: Quantity d a -> AnyQuantity a

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

The class of types that can be used to model Quantitys whose Dimensions are only known dynamically.

Minimal complete definition

promotableIn, promotableOut

Instances
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods

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

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.

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.

Instances
 Source # Instance details Methods Source # Instance details Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods (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 MethodsdynamicDimension :: Proxy (Dim l m t i th n j) -> DynamicDimension Source # KnownDimension d => HasDynamicDimension (Dimensional v d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methods

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
 Source # Instance details Methods Source # Instance details Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DynamicDimension -> c DynamicDimension #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c DynamicDimension #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c DynamicDimension) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DynamicDimension) #gmapT :: (forall b. Data b => b -> b) -> DynamicDimension -> DynamicDimension #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DynamicDimension -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DynamicDimension -> r #gmapQ :: (forall d. Data d => d -> u) -> DynamicDimension -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> DynamicDimension -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> DynamicDimension -> m DynamicDimension #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DynamicDimension -> m DynamicDimension #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DynamicDimension -> m DynamicDimension # Source # Instance details Methods Source # Instance details MethodsshowList :: [DynamicDimension] -> ShowS # Source # Instance details Associated Typestype Rep DynamicDimension :: Type -> Type # Methods Source # Instance details Methodsrnf :: DynamicDimension -> () # Source # Instance details Methods Source # Instance details type Rep DynamicDimension = D1 (MetaData "DynamicDimension" "Numeric.Units.Dimensional.Dimensions.TermLevel" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" 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.

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

A DynQuantity which corresponds to zero value of any dimension.

When combined through arithmetic with other DynQuantitys, 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 DynQuantitys of a specific dimension.

# Dynamic Units

data AnyUnit Source #

A Unit whose Dimension is only known dynamically.

Instances
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic MethodsshowList :: [AnyUnit] -> ShowS # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Associated Typestype Rep AnyUnit :: Type -> Type # Methodsto :: Rep AnyUnit x -> AnyUnit # Source # AnyUnits form a Semigroup under multiplication. Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsstimes :: Integral b => b -> AnyUnit -> AnyUnit # Source # AnyUnits form a Monoid under multiplication. Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methodsmconcat :: [AnyUnit] -> AnyUnit # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic Methods type Rep AnyUnit Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic type Rep AnyUnit = D1 (MetaData "AnyUnit" "Numeric.Units.Dimensional.Dynamic" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" 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.

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.

The dynamic SI coherent unit of a given dimension.

## Arithmetic on Dynamic Units

Forms the product of two dynamic units.

Forms the quotient of two dynamic units.

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

Raises a dynamic unit to an integer power.

Forms the reciprocal of a dynamic unit.

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