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

Copyright Copyright (C) 2006-2018 Bjorn Buckwalter BSD3 bjorn@buckwalter.se Experimental GHC only? None Haskell2010

Numeric.Units.Dimensional.FixedPoint

Description

Defines types for manipulation of quantities with fixed point representations.

Synopsis

# Types

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.

data family Dimensional v :: Dimension -> Type -> Type Source #

A dimensional value, either a Quantity or a Unit, parameterized by its Dimension and representation.

Instances
 Vector Vector a => Vector Vector (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsbasicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (SQuantity s d a) -> m (Vector (SQuantity s d a)) #basicUnsafeThaw :: PrimMonad m => Vector (SQuantity s d a) -> m (Mutable Vector (PrimState m) (SQuantity s d a)) #basicLength :: Vector (SQuantity s d a) -> Int #basicUnsafeSlice :: Int -> Int -> Vector (SQuantity s d a) -> Vector (SQuantity s d a) #basicUnsafeIndexM :: Monad m => Vector (SQuantity s d a) -> Int -> m (SQuantity s d a) #basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (SQuantity s d a) -> Vector (SQuantity s d a) -> m () #elemseq :: Vector (SQuantity s d a) -> SQuantity s d a -> b -> b # MVector MVector a => MVector MVector (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsbasicLength :: MVector s0 (SQuantity s d a) -> Int #basicUnsafeSlice :: Int -> Int -> MVector s0 (SQuantity s d a) -> MVector s0 (SQuantity s d a) #basicOverlaps :: MVector s0 (SQuantity s d a) -> MVector s0 (SQuantity s d a) -> Bool #basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (SQuantity s d a)) #basicInitialize :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> m () #basicUnsafeReplicate :: PrimMonad m => Int -> SQuantity s d a -> m (MVector (PrimState m) (SQuantity s d a)) #basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> Int -> m (SQuantity s d a) #basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> Int -> SQuantity s d a -> m () #basicClear :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> m () #basicSet :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> SQuantity s d a -> m () #basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> MVector (PrimState m) (SQuantity s d a) -> m () #basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> MVector (PrimState m) (SQuantity s d a) -> m () #basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (SQuantity s d a) -> Int -> m (MVector (PrimState m) (SQuantity s d a)) # Source # Instance detailsDefined in Numeric.Units.Dimensional.Dynamic MethodsdemotableOut :: Quantity d a -> AnyQuantity a Generic1 (Dimensional (DQuantity s) d :: Type -> Type) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Associated Typestype Rep1 (Dimensional (DQuantity s) d) :: k -> Type # Methodsfrom1 :: Dimensional (DQuantity s) d a -> Rep1 (Dimensional (DQuantity s) d) a #to1 :: Rep1 (Dimensional (DQuantity s) d) a -> Dimensional (DQuantity s) d a # Generic1 (Dimensional (DUnit m) d :: Type -> Type) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Associated Typestype Rep1 (Dimensional (DUnit m) d) :: k -> Type # Methodsfrom1 :: Dimensional (DUnit m) d a -> Rep1 (Dimensional (DUnit m) d) a #to1 :: Rep1 (Dimensional (DUnit m) d) a -> Dimensional (DUnit m) d a # KnownVariant v => Functor (Dimensional v d) Source # A Functor instance for Dimensional.Note that this instance is dubious, because it allows you to break the dimensional abstraction. See dmap for more information.Note that, while this instance overlaps with that given for Dimensionless, it is confluent with that instance.Note that this is an orphan instance. Instance detailsDefined in Numeric.Units.Dimensional.Functor Methodsfmap :: (a -> b) -> Dimensional v d a -> Dimensional v d b #(<$) :: a -> Dimensional v d b -> Dimensional v d a # Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methodsfmap :: (a -> b) -> SQuantity s DOne a -> SQuantity s DOne b #(<$) :: a -> SQuantity s DOne b -> SQuantity s DOne a # Eq1 (SQuantity s d) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsliftEq :: (a -> b -> Bool) -> SQuantity s d a -> SQuantity s d b -> Bool # Ord1 (SQuantity s d) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsliftCompare :: (a -> b -> Ordering) -> SQuantity s d a -> SQuantity s d b -> Ordering # NFData a => NFData (Quantity d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methodsrnf :: Quantity d a -> () # Bounded a => Bounded (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsminBound :: SQuantity s d a #maxBound :: SQuantity s d a # Eq a => Eq (Dimensional (DQuantity s) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methods(==) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool #(/=) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool # (Typeable s, Typeable d, Data a) => Data (Dimensional (DQuantity s) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methodsgfoldl :: (forall d0 b. Data d0 => c (d0 -> b) -> d0 -> c b) -> (forall g. g -> c g) -> Dimensional (DQuantity s) d a -> c (Dimensional (DQuantity s) d a) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Dimensional (DQuantity s) d a) #toConstr :: Dimensional (DQuantity s) d a -> Constr #dataTypeOf :: Dimensional (DQuantity s) d a -> DataType #dataCast1 :: Typeable t => (forall d0. Data d0 => c (t d0)) -> Maybe (c (Dimensional (DQuantity s) d a)) #dataCast2 :: Typeable t => (forall d0 e. (Data d0, Data e) => c (t d0 e)) -> Maybe (c (Dimensional (DQuantity s) d a)) #gmapT :: (forall b. Data b => b -> b) -> Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a #gmapQl :: (r -> r' -> r) -> r -> (forall d0. Data d0 => d0 -> r') -> Dimensional (DQuantity s) d a -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d0. Data d0 => d0 -> r') -> Dimensional (DQuantity s) d a -> r #gmapQ :: (forall d0. Data d0 => d0 -> u) -> Dimensional (DQuantity s) d a -> [u] #gmapQi :: Int -> (forall d0. Data d0 => d0 -> u) -> Dimensional (DQuantity s) d a -> u #gmapM :: Monad m => (forall d0. Data d0 => d0 -> m d0) -> Dimensional (DQuantity s) d a -> m (Dimensional (DQuantity s) d a) #gmapMp :: MonadPlus m => (forall d0. Data d0 => d0 -> m d0) -> Dimensional (DQuantity s) d a -> m (Dimensional (DQuantity s) d a) #gmapMo :: MonadPlus m => (forall d0. Data d0 => d0 -> m d0) -> Dimensional (DQuantity s) d a -> m (Dimensional (DQuantity s) d a) # Ord a => Ord (Dimensional (DQuantity s) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methodscompare :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Ordering #(<) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool #(<=) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool #(>) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool #(>=) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool #max :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a #min :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a # (KnownDimension d, KnownExactPi s, Show a, Real a) => Show (SQuantity s d a) Source # Uses non-breaking spaces between the value and the unit, and within the unit name. Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsshowsPrec :: Int -> SQuantity s d a -> ShowS #show :: SQuantity s d a -> String #showList :: [SQuantity s d a] -> ShowS # Show a => Show (Unit m d a) Source # Unit names are shown with non-breaking spaces. Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodsshowsPrec :: Int -> Unit m d a -> ShowS #show :: Unit m d a -> String #showList :: [Unit m d a] -> ShowS # Generic (Dimensional (DQuantity s) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Associated Typestype Rep (Dimensional (DQuantity s) d a) :: Type -> Type # Methodsfrom :: Dimensional (DQuantity s) d a -> Rep (Dimensional (DQuantity s) d a) x #to :: Rep (Dimensional (DQuantity s) d a) x -> Dimensional (DQuantity s) d a # Generic (Dimensional (DUnit m) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Associated Typestype Rep (Dimensional (DUnit m) d a) :: Type -> Type # Methodsfrom :: Dimensional (DUnit m) d a -> Rep (Dimensional (DUnit m) d a) x #to :: Rep (Dimensional (DUnit m) d a) x -> Dimensional (DUnit m) d a # Num a => Semigroup (SQuantity s d a) Source # Quantitys of a given Dimension form a Semigroup under addition. Instance detailsDefined in Numeric.Units.Dimensional.Internal Methods(<>) :: SQuantity s d a -> SQuantity s d a -> SQuantity s d a #sconcat :: NonEmpty (SQuantity s d a) -> SQuantity s d a #stimes :: Integral b => b -> SQuantity s d a -> SQuantity s d a # Num a => Monoid (SQuantity s d a) Source # Quantitys of a given Dimension form a Monoid under addition. Instance detailsDefined in Numeric.Units.Dimensional.Internal Methodsmempty :: SQuantity s d a #mappend :: SQuantity s d a -> SQuantity s d a -> SQuantity s d a #mconcat :: [SQuantity s d a] -> SQuantity s d a # Storable a => Storable (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal MethodssizeOf :: SQuantity s d a -> Int #alignment :: SQuantity s d a -> Int #peekElemOff :: Ptr (SQuantity s d a) -> Int -> IO (SQuantity s d a) #pokeElemOff :: Ptr (SQuantity s d a) -> Int -> SQuantity s d a -> IO () #peekByteOff :: Ptr b -> Int -> IO (SQuantity s d a) #pokeByteOff :: Ptr b -> Int -> SQuantity s d a -> IO () #peek :: Ptr (SQuantity s d a) -> IO (SQuantity s d a) #poke :: Ptr (SQuantity s d a) -> SQuantity s d a -> IO () # AEq a => AEq (Dimensional (DQuantity s) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methods(===) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool #(~==) :: Dimensional (DQuantity s) d a -> Dimensional (DQuantity s) d a -> Bool # Unbox a => Unbox (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal KnownDimension d => HasDimension (Dimensional v d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methodsdimension :: Dimensional v d a -> Dimension' Source # KnownDimension d => HasDynamicDimension (Dimensional v d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methods HasInterchangeName (Unit m d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Methods data MVector v (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal data MVector v (SQuantity s d a) = MV_Quantity {unMVQ :: MVector v a} data Dimensional (DQuantity s) d a Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal data Dimensional (DQuantity s) d a = Quantity a data Dimensional (DUnit m) d a Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal data Dimensional (DUnit m) d a = Unit !(UnitName m) !ExactPi !a type Rep1 (Dimensional (DQuantity s) d :: Type -> Type) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal type Rep1 (Dimensional (DQuantity s) d :: Type -> Type) = D1 (MetaData "Dimensional" "Numeric.Units.Dimensional.Internal" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" True) (C1 (MetaCons "Quantity" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1)) type Rep1 (Dimensional (DUnit m) d :: Type -> Type) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal type Rep1 (Dimensional (DUnit m) d :: Type -> Type) = D1 (MetaData "Dimensional" "Numeric.Units.Dimensional.Internal" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" False) (C1 (MetaCons "Unit" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (UnitName m)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ExactPi) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) Par1))) type Rep (Dimensional (DQuantity s) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal type Rep (Dimensional (DQuantity s) d a) = D1 (MetaData "Dimensional" "Numeric.Units.Dimensional.Internal" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" True) (C1 (MetaCons "Quantity" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) type Rep (Dimensional (DUnit m) d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal type Rep (Dimensional (DUnit m) d a) = D1 (MetaData "Dimensional" "Numeric.Units.Dimensional.Internal" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" False) (C1 (MetaCons "Unit" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (UnitName m)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ExactPi) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)))) data Vector (SQuantity s d a) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal data Vector (SQuantity s d a) = V_Quantity {unVQ :: Vector a}

type Unit (m :: Metricality) = Dimensional (DUnit m) Source #

A unit of measurement.

A dimensional quantity.

type SQuantity s = Dimensional (DQuantity s) Source #

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.

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
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Variants Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Variants Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Metricality -> c Metricality #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Metricality #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Metricality) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Metricality) #gmapT :: (forall b. Data b => b -> b) -> Metricality -> Metricality #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Metricality -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Metricality -> r #gmapQ :: (forall d. Data d => d -> u) -> Metricality -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Metricality -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Metricality -> m Metricality #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Metricality -> m Metricality #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Metricality -> m Metricality # Source # Instance detailsDefined in Numeric.Units.Dimensional.Variants Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Variants Associated Typestype Rep Metricality :: Type -> Type # Methods Source # Instance detailsDefined in Numeric.Units.Dimensional.Variants Methodsrnf :: Metricality -> () # type Rep Metricality Source # Instance detailsDefined in Numeric.Units.Dimensional.Variants type Rep Metricality = D1 (MetaData "Metricality" "Numeric.Units.Dimensional.Variants" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" False) (C1 (MetaCons "Metric" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "NonMetric" PrefixI False) (U1 :: Type -> Type))

# Physical Dimensions

data Dimension Source #

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'

Constructors

 Dim TypeInt TypeInt TypeInt TypeInt TypeInt TypeInt TypeInt
Instances
 (KnownTypeInt l, KnownTypeInt m, KnownTypeInt t, KnownTypeInt i, KnownTypeInt th, KnownTypeInt n, KnownTypeInt j) => HasDimension (Proxy (Dim l m t i th n j)) Source # Instance details Methodsdimension :: Proxy (Dim l m t i th n j) -> Dimension' 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 MethodsdynamicDimension :: Proxy (Dim l m t i th n j) -> DynamicDimension Source #

## Dimension Arithmetic

type family (a :: Dimension) * (b :: Dimension) where ... infixl 7 Source #

Multiplication of dimensions corresponds to adding 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')

type family (a :: Dimension) / (d :: Dimension) where ... infixl 7 Source #

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')

type family (d :: Dimension) ^ (x :: TypeInt) where ... infixr 8 Source #

Powers of dimensions corresponds 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

 DOne ^ x = DOne d ^ Zero = DOne d ^ Pos1 = d (Dim l m t i th n j) ^ x = Dim (l * x) (m * x) (t * x) (i * x) (th * x) (n * x) (j * x)

type family NRoot (d :: Dimension) (x :: TypeInt) where ... Source #

Roots of dimensions corresponds to division of the base dimensions' exponents by the order of the root.

Equations

 NRoot DOne x = DOne NRoot d Pos1 = d NRoot (Dim l m t i th n j) x = Dim (l / x) (m / x) (t / x) (i / x) (th / x) (n / x) (j / x)

type Recip (d :: Dimension) = DOne / d Source #

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

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

 Dim' !Int !Int !Int !Int !Int !Int !Int
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) -> Dimension' -> c Dimension' #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Dimension' #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Dimension') #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Dimension') #gmapT :: (forall b. Data b => b -> b) -> Dimension' -> Dimension' #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Dimension' -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Dimension' -> r #gmapQ :: (forall d. Data d => d -> u) -> Dimension' -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Dimension' -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Dimension' -> m Dimension' #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Dimension' -> m Dimension' #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Dimension' -> m Dimension' # Source # Instance details Methods Source # Instance details MethodsshowList :: [Dimension'] -> ShowS # Source # Instance details Associated Typestype Rep Dimension' :: Type -> Type # Methods Source # Instance details Methodsstimes :: Integral b => b -> Dimension' -> Dimension' # Source # The monoid of dimensions under multiplication. Instance details Methodsmconcat :: [Dimension'] -> Dimension' # Source # Instance details Methodsrnf :: Dimension' -> () # Source # Instance details Methods Source # Instance details Methods type Rep Dimension' Source # Instance details type Rep Dimension' = D1 (MetaData "Dimension'" "Numeric.Units.Dimensional.Dimensions.TermLevel" "dimensional-1.3-7Gh1mp5ZBGaGfkDr7lUYf2" False) (C1 (MetaCons "Dim'" PrefixI False) ((S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int))) :*: ((S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int)))))

class HasDynamicDimension a => HasDimension a where Source #

Dimensional values inhabit this class, which allows access to a term-level representation of their dimension.

Methods

dimension :: a -> Dimension' Source #

Obtains a term-level representation of a value's dimension.

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

type KnownDimension (d :: Dimension) = HasDimension (Proxy d) Source #

A KnownDimension is one for which we can construct a term-level representation. Each validly constructed type of kind Dimension has a KnownDimension instance.

While KnownDimension is a constraint synonym, the presence of KnownDimension d in a context allows use of dimension :: Proxy d -> Dimension'.

# Dimensional Arithmetic

(*~) :: forall s m d a b. (RealFrac a, Integral b, MinCtxt s a) => a -> Unit m d a -> SQuantity s d b infixl 7 Source #

Forms a possibly scaled SQuantity by multipliying a number and a unit.

(/~) :: forall s m d a b. (Real a, Fractional b, MinCtxt s b) => SQuantity s d a -> Unit m d b -> b infixl 7 Source #

Divides a possibly scaled SQuantity by a Unit of the same physical dimension, obtaining the numerical value of the quantity expressed in that unit.

(*) :: (KnownVariant v1, KnownVariant v2, KnownVariant (v1 * v2), Num a) => Dimensional v1 d1 a -> Dimensional v2 d2 a -> Dimensional (v1 * v2) (d1 * d2) a infixl 7 Source #

Multiplies two Quantitys or two Units.

The intimidating type signature captures the similarity between these operations and ensures that composite Units are NonMetric.

(/) :: (KnownVariant v1, KnownVariant v2, KnownVariant (v1 / v2), Fractional a) => Dimensional v1 d1 a -> Dimensional v2 d2 a -> Dimensional (v1 / v2) (d1 / d2) a infixl 7 Source #

Divides one Quantity by another or one Unit by another.

The intimidating type signature captures the similarity between these operations and ensures that composite Units are NotPrefixable.

(+) :: Num a => SQuantity s d a -> SQuantity s d a -> SQuantity s d a infixl 6 Source #

Adds two possibly scaled SQuantitys, preserving any scale factor.

Use in conjunction with changeRepRound to combine quantities with differing scale factors.

(-) :: Num a => SQuantity s d a -> SQuantity s d a -> SQuantity s d a infixl 6 Source #

Subtracts one possibly scaled SQuantity from another, preserving any scale factor.

Use in conjunction with changeRepRound to combine quantities with differing scale factors.

negate :: Num a => SQuantity s d a -> SQuantity s d a Source #

Negates the value of a possibly scaled SQuantity, preserving any scale factor.

abs :: Num a => SQuantity s d a -> SQuantity s d a Source #

Takes the absolute value of a possibly scaled SQuantity, preserving any scale factor.

## Transcendental Functions

### Via Double

atan2D :: (Integral a, Integral b, MinCtxt s1 Double, MinCtxt s2 Double, MinCtxt s3 Double) => SQuantity s1 DOne a -> SQuantity s2 DOne a -> SQuantity s3 DOne b Source #

The standard two argument arctangent function. Since it interprets its two arguments in comparison with one another, the input may have any dimension.

### Via arbitary Floating type

expVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

logVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

sinVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

cosVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

tanVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

asinVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

acosVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

atanVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

sinhVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

coshVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

tanhVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

asinhVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

acoshVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

atanhVia :: (Integral a, RealFrac b, Floating b, Integral c, MinCtxt s1 b, MinCtxt s2 b) => Proxy b -> SQuantity s1 DOne a -> SQuantity s2 DOne c Source #

atan2Via :: forall s1 s2 s3 a b c d. (Integral a, RealFloat b, Integral c, MinCtxt s1 b, MinCtxt s2 b, MinCtxt s3 b, KnownDimension d) => Proxy b -> SQuantity s1 d a -> SQuantity s2 d a -> SQuantity s3 DOne c Source #

The standard two argument arctangent function. Since it interprets its two arguments in comparison with one another, the input may have any dimension.

## Operations on Collections

(*~~) :: (Functor f, RealFrac a, Integral b, MinCtxt s a) => f a -> Unit m d a -> f (SQuantity s d b) infixl 7 Source #

Applies *~ to all values in a functor.

(/~~) :: (Functor f, Real a, Fractional b, MinCtxt s b) => f (SQuantity s d a) -> Unit m d b -> f b infixl 7 Source #

Applies /~ to all values in a functor.

sum :: (Num a, Foldable f) => f (SQuantity s d a) -> SQuantity s d a Source #

The sum of all elements in a list.

mean :: (Fractional a, Foldable f) => f (SQuantity s d a) -> SQuantity s d a Source #

The arithmetic mean of all elements in a list.

## Conversion Between Representations

rescale :: forall a b d s1 s2. (Integral a, Integral b, KnownExactPi s1, KnownExactPi s2) => SQuantity s1 d a -> SQuantity s2 d b Source #

Rescales a fixed point quantity, accomodating changes both in its scale factor and its representation type.

Note that this uses an arbitrary precision representation of pi, which may be quite slow.

rescaleFinite :: (Integral a, FiniteBits a, Integral b, FiniteBits b, KnownExactPi s1, KnownExactPi s2) => SQuantity s1 d a -> SQuantity s2 d b Source #

Rescales a fixed point quantity, accomodating changes both in its scale factor and its representation type.

Expected to outperform rescale when a FiniteBits context is available for the source and destination representation types.

rescaleD :: (Integral a, Integral b, KnownExactPi s1, KnownExactPi s2) => SQuantity s1 d a -> SQuantity s2 d b Source #

Approximately rescales a fixed point quantity, accomodating changes both in its scale factor and its representation type.

Uses approximate arithmetic by way of an intermediate Double representation.

rescaleVia :: forall a b c d s1 s2. (Integral a, RealFrac b, Floating b, Integral c, KnownExactPi s1, KnownExactPi s2) => Proxy b -> SQuantity s1 d a -> SQuantity s2 d c Source #

Approximately rescales a fixed point quantity, accomodating changes both in its scale factor and its representation type.

Uses approximate arithmetic by way of an intermediate Floating type, to which a proxy must be supplied.

class KnownVariant (v :: Variant) where Source #

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.

Minimal complete definition

extractValue, extractName, injectValue, dmap

Methods

dmap :: (a1 -> a2) -> Dimensional v d a1 -> Dimensional v d a2 Source #

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.

Instances
 Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Associated Typesdata Dimensional (DQuantity s) a b :: Type Source #type ScaleFactor (DQuantity s) :: ExactPi' MethodsextractValue :: Dimensional (DQuantity s) d a -> (a, Maybe ExactPi)extractName :: Dimensional (DQuantity s) d a -> Maybe (UnitName NonMetric)injectValue :: Maybe (UnitName NonMetric) -> (a, Maybe ExactPi) -> Dimensional (DQuantity s) d admap :: (a1 -> a2) -> Dimensional (DQuantity s) d a1 -> Dimensional (DQuantity s) d a2 Source # Typeable m => KnownVariant (DUnit m) Source # Instance detailsDefined in Numeric.Units.Dimensional.Internal Associated Typesdata Dimensional (DUnit m) a b :: Type Source #type ScaleFactor (DUnit m) :: ExactPi' MethodsextractValue :: Dimensional (DUnit m) d a -> (a, Maybe ExactPi)extractName :: Dimensional (DUnit m) d a -> Maybe (UnitName NonMetric)injectValue :: Maybe (UnitName NonMetric) -> (a, Maybe ExactPi) -> Dimensional (DUnit m) d admap :: (a1 -> a2) -> Dimensional (DUnit m) d a1 -> Dimensional (DUnit m) d a2 Source #

changeRep :: forall v1 v2 d a b. (KnownVariant v1, KnownVariant v2, CompatibleVariants v1 v2, MinCtxt (ScaleFactor v1 / ScaleFactor v2) b, Real a, Fractional b) => Dimensional v1 d a -> Dimensional v2 d b Source #

Convenient conversion between numerical types while retaining dimensional information.

changeRepRound :: forall v1 v2 d a b. (KnownVariant v1, KnownVariant v2, CompatibleVariants v1 v2, MinCtxt (ScaleFactor v1 / ScaleFactor v2) a, RealFrac a, Integral b) => Dimensional v1 d a -> Dimensional v2 d b Source #

Convenient conversion to types with Integral representations using round.

changeRepApproximate :: (KnownVariant v, Floating b) => Dimensional v d ExactPi -> Dimensional v d b Source #

Convenient conversion from exactly represented values while retaining dimensional information.

# Dimension Synonyms

The type-level dimension of dimensionless values.

# Constants

_0 :: Num a => SQuantity s d a Source #

The constant for zero is polymorphic, allowing it to express zero Length or Capacitance or Velocity etc, in addition to the Dimensionless value zero.

epsilon :: Integral a => SQuantity s d a Source #

The least 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.

tau :: (Integral a, KnownExactPi s) => SQuantity s DOne a Source #

Twice pi.

For background on tau see http://tauday.com/tau-manifesto (but also feel free to review http://www.thepimanifesto.com).

# Constructing Units

siUnit :: forall d a. (KnownDimension d, Num a) => Unit NonMetric d a Source #

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.

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 "boxing" of dimensionless values.

mkUnitR :: Floating a => UnitName m -> ExactPi -> Unit m1 d a -> Unit m d a Source #

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.

mkUnitQ :: Fractional a => UnitName m -> Rational -> Unit m1 d a -> Unit m d a Source #

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 rational. See mkUnitZ for when it is an integer and mkUnitR for the general case.

For more information see mkUnitR.

mkUnitZ :: Num a => UnitName m -> Integer -> Unit m1 d a -> Unit m d a Source #

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.

name :: Unit m d a -> UnitName m Source #

Extracts the UnitName of a Unit.

exactValue :: Unit m d a -> ExactPi Source #

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.

weaken :: Unit m d a -> Unit NonMetric d a Source #

Discards potentially unwanted type level information about a Unit.

strengthen :: Unit m d a -> Maybe (Unit Metric d a) Source #

Attempts to convert a Unit which may or may not be Metric to one which is certainly Metric.

exactify :: Unit m d a -> Unit m d ExactPi Source #

Forms the exact version of a Unit.

# Commonly Used Type Synonyms

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

type Q n a = SQuantity (QScale n) DOne a Source #

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

type QScale n = One / ExactNatural (2 ^ n) Source #

A binary scale factor.

A single-turn angle represented as a signed 8-bit integer.

A single-turn angle represented as a signed 16-bit integer.

A single-turn angle represented as a signed 32-bit integer.