Copyright | Copyright (C) 2006-2018 Bjorn Buckwalter |
---|---|
License | BSD3 |
Maintainer | bjorn@buckwalter.se |
Stability | Stable |
Portability | GHC only? |
Safe Haskell | None |
Language | Haskell2010 |
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
- 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 #
Instances
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
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.
demotableOut
Instances
Demotable AnyQuantity Source # | |
Defined in Numeric.Units.Dimensional.Dynamic demotableOut :: AnyQuantity a -> AnyQuantity a | |
KnownDimension d => Demotable (Quantity d) Source # | |
Defined in Numeric.Units.Dimensional.Dynamic demotableOut :: Quantity d a -> AnyQuantity a |
class Promotable (q :: Type -> Type) Source #
promotableIn, promotableOut
Instances
Promotable DynQuantity Source # | |
Defined in Numeric.Units.Dimensional.Dynamic promotableIn :: AnyQuantity a -> DynQuantity a promotableOut :: DynQuantity a -> DynQuantity a | |
Promotable AnyQuantity Source # | |
Defined in Numeric.Units.Dimensional.Dynamic promotableIn :: AnyQuantity a -> AnyQuantity a promotableOut :: AnyQuantity 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.
Nothing
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.
dynamicDimension :: HasDimension a => 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.
Instances
HasDynamicDimension DynamicDimension Source # | |
HasDynamicDimension Dimension' Source # | |
HasDynamicDimension AnyUnit Source # | |
Defined in Numeric.Units.Dimensional.Dynamic | |
HasDynamicDimension (DynQuantity a) Source # | |
Defined in Numeric.Units.Dimensional.Dynamic | |
HasDynamicDimension (AnyQuantity a) Source # | |
Defined in Numeric.Units.Dimensional.Dynamic | |
(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 # | |
Defined in Numeric.Units.Dimensional.Dimensions.TypeLevel dynamicDimension :: Proxy (Dim l m t i th n j) -> DynamicDimension Source # | |
KnownDimension d => HasDynamicDimension (Dimensional v d a) Source # | |
Defined in Numeric.Units.Dimensional.Internal dynamicDimension :: Dimensional v d a -> DynamicDimension Source # |
data DynamicDimension Source #
The dimension of a dynamic value, which may not have any dimension at all.
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
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
Instances
Show AnyUnit Source # | |
Generic AnyUnit Source # | |
Semigroup AnyUnit Source # | |
Monoid AnyUnit Source # | |
HasDimension AnyUnit Source # | |
Defined in Numeric.Units.Dimensional.Dynamic dimension :: AnyUnit -> Dimension' Source # | |
HasDynamicDimension AnyUnit Source # | |
Defined in Numeric.Units.Dimensional.Dynamic | |
HasInterchangeName AnyUnit Source # | |
Defined in Numeric.Units.Dimensional.Dynamic | |
type Rep AnyUnit Source # | |
Defined 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 #
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.