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

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

Numeric.Units.Dimensional.Dimensions

Description

Provides both term-level and type-level representations for physical dimensions in a single import for convenience.

Presuming that users intend to work primarily with type level dimensions, this module hides arithmetic operators over term level dimensions and aliases for the base term-level dimensions to avoid namespace pollution. These features are available directly from Numeric.Units.Dimensional.Dimensions.TermLevel if desired.

Synopsis

- class HasDynamicDimension a => HasDimension a where
  - dimension :: a -> Dimension'
- class HasDynamicDimension a where
  - dynamicDimension :: a -> DynamicDimension
- data DynamicDimension
  - = NoDimension
  - | SomeDimension Dimension'
  - | AnyDimension
- data Dimension' = Dim' !Int !Int !Int !Int !Int !Int !Int
- matchDimensions :: DynamicDimension -> DynamicDimension -> DynamicDimension
- isCompatibleWith :: HasDynamicDimension a => a -> Dimension' -> Bool
- hasSomeDimension :: HasDynamicDimension a => a -> Bool
- dOne :: Dimension'
- asList :: Dimension' -> [Int]
- module Numeric.Units.Dimensional.Dimensions.TypeLevel

# Documentation

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

Instances details

HasDimension Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dimension :: Dimension' -> Dimension' Source #
HasDimension AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dimension :: AnyUnit -> Dimension' Source #
HasDimension (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dimension :: AnyQuantity a -> Dimension' Source #
(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 Defined in Numeric.Units.Dimensional.Dimensions.TypeLevel Methods dimension :: Proxy ('Dim l m t i th n j) -> Dimension' Source #
KnownDimension d => HasDimension (Dimensional v d a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Internal Methods dimension :: Dimensional v d a -> Dimension' Source #

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 DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dynamicDimension :: DynamicDimension -> DynamicDimension Source #
HasDynamicDimension Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dynamicDimension :: Dimension' -> DynamicDimension Source #
HasDynamicDimension AnyUnit Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: AnyUnit -> DynamicDimension Source #
HasDynamicDimension (DynQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: DynQuantity a -> DynamicDimension Source #
HasDynamicDimension (AnyQuantity a) Source # |
Instance details Defined in Numeric.Units.Dimensional.Dynamic Methods dynamicDimension :: AnyQuantity 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

Eq DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods (==) :: DynamicDimension -> DynamicDimension -> Bool # (/=) :: DynamicDimension -> DynamicDimension -> Bool #
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

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

toConstr :: DynamicDimension -> Constr

dataTypeOf :: DynamicDimension -> DataType

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 :: forall r r'. (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

Ord DynamicDimension Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dimensions.TermLevel

Methods

compare :: DynamicDimension -> DynamicDimension -> Ordering #

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

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

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

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

max :: DynamicDimension -> DynamicDimension -> DynamicDimension #

min :: DynamicDimension -> DynamicDimension -> DynamicDimension #

Show DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods showsPrec :: Int -> DynamicDimension -> ShowS # show :: DynamicDimension -> String # showList :: [DynamicDimension] -> ShowS #
Generic DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Associated Types type Rep DynamicDimension :: Type -> Type Methods from :: DynamicDimension -> Rep DynamicDimension x to :: Rep DynamicDimension x -> DynamicDimension
NFData DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods rnf :: DynamicDimension -> ()
HasDynamicDimension DynamicDimension Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods 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.3-C8v0k83E9Py18UKTdF1oLh" '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)))

data Dimension' Source #

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

Instances details

Eq Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods (==) :: Dimension' -> Dimension' -> Bool # (/=) :: Dimension' -> Dimension' -> Bool #
Data Dimension' 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) -> Dimension' -> c Dimension'

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Dimension'

toConstr :: Dimension' -> Constr

dataTypeOf :: Dimension' -> DataType

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 :: forall r r'. (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'

Ord Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods compare :: Dimension' -> Dimension' -> Ordering # (<) :: Dimension' -> Dimension' -> Bool # (<=) :: Dimension' -> Dimension' -> Bool # (>) :: Dimension' -> Dimension' -> Bool # (>=) :: Dimension' -> Dimension' -> Bool # max :: Dimension' -> Dimension' -> Dimension' # min :: Dimension' -> Dimension' -> Dimension' #
Show Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods showsPrec :: Int -> Dimension' -> ShowS # show :: Dimension' -> String # showList :: [Dimension'] -> ShowS #
Generic Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Associated Types type Rep Dimension' :: Type -> Type Methods from :: Dimension' -> Rep Dimension' x to :: Rep Dimension' x -> Dimension'
Semigroup Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods (<>) :: Dimension' -> Dimension' -> Dimension' # sconcat :: NonEmpty Dimension' -> Dimension' stimes :: Integral b => b -> Dimension' -> Dimension'
Monoid Dimension' Source # | The monoid of dimensions under multiplication.
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods mempty :: Dimension' # mappend :: Dimension' -> Dimension' -> Dimension' # mconcat :: [Dimension'] -> Dimension' #
NFData Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods rnf :: Dimension' -> ()
HasDimension Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dimension :: Dimension' -> Dimension' Source #
HasDynamicDimension Dimension' Source # |
Instance details Defined in Numeric.Units.Dimensional.Dimensions.TermLevel Methods dynamicDimension :: Dimension' -> DynamicDimension Source #
type Rep Dimension' Source # |

Instance details

Defined in Numeric.Units.Dimensional.Dimensions.TermLevel

type Rep Dimension' = D1 ('MetaData "Dimension'" "Numeric.Units.Dimensional.Dimensions.TermLevel" "dimensional-1.3-C8v0k83E9Py18UKTdF1oLh" '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)))))

matchDimensions :: DynamicDimension -> DynamicDimension -> DynamicDimension Source #

Combines two `DynamicDimension`s, determining the `DynamicDimension` of a quantity that must match both inputs.

This is the lattice meet operation for `DynamicDimension`.

isCompatibleWith :: HasDynamicDimension a => a -> Dimension' -> Bool Source #

Determines if a value that has a `DynamicDimension` is compatible with a specified `Dimension'`.

hasSomeDimension :: HasDynamicDimension a => a -> Bool Source #

Determines if a value that has a `DynamicDimension` in fact has any valid dimension at all.

dOne :: Dimension' Source #

The dimension of dimensionless values.

asList :: Dimension' -> [Int] Source #

Converts a dimension to a list of 7 integers, representing the exponent associated with each of the 7 SI base dimensions in the standard order.

module Numeric.Units.Dimensional.Dimensions.TypeLevel