Copyright | (C) 2013 Richard Eisenberg |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | Richard Eisenberg (rae@cs.brynmawr.edu) |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This file gathers and exports user-visible type-level definitions, to make error messages less cluttered. Non-expert users should never have to use the definitions exported from this module.
Synopsis
- type family Lookup (dim :: *) (lcsu :: LCSU *) :: * where ...
- type family LookupList (keys :: [Factor *]) (map :: LCSU *) :: [Factor *] where ...
- type family ConvertibleLCSUs (dfactors :: [Factor *]) (l1 :: LCSU *) (l2 :: LCSU *) :: Constraint where ...
- type family ValidDLU (dfactors :: [Factor *]) (lcsu :: LCSU *) (unit :: *) where ...
- type family ValidDL (dfactors :: [Factor *]) (lcsu :: LCSU *) :: Constraint where ...
- type family (units1 :: [Factor *]) *~ (units2 :: [Factor *]) :: Constraint where ...
- type family CanonicalUnitsOfFactors (fs :: [Factor *]) :: [*] where ...
- type family DimOfUnitIsConsistent unit :: Constraint where ...
- type family IsCanonical (unit :: *) where ...
- type CanonicalUnit (unit :: *) = CanonicalUnit' (BaseUnit unit) unit
- type family CanonicalUnit' (base_unit :: *) (unit :: *) :: * where ...
- type family BaseHasConvRatio unit where ...
- class Units units => UnitFactor (units :: [Factor *])
- type family UnitFactorsOf unit :: [Factor *]
- data Factor star = F star Z
- type family (a :: Factor *) $= (b :: Factor *) :: Bool where ...
- type family Extract (s :: Factor *) (lst :: [Factor *]) :: ([Factor *], Maybe (Factor *)) where ...
- type family Reorder (a :: [Factor *]) (b :: [Factor *]) :: [Factor *] where ...
- type family Reorder' (scrut :: ([Factor *], Maybe (Factor *))) (t :: [Factor *]) :: [Factor *] where ...
- type family (a :: [Factor *]) @~ (b :: [Factor *]) :: Constraint where ...
- type family Normalize (d :: [Factor *]) :: [Factor *] where ...
- type family (a :: [Factor *]) @@+ (b :: [Factor *]) :: [Factor *] where ...
- type family (a :: [Factor *]) @+ (b :: [Factor *]) :: [Factor *] where ...
- type family (a :: [Factor *]) @@- (b :: [Factor *]) :: [Factor *] where ...
- type family (a :: [Factor *]) @- (b :: [Factor *]) :: [Factor *] where ...
- type family NegDim (a :: Factor *) :: Factor * where ...
- type family NegList (a :: [Factor *]) :: [Factor *] where ...
- type family (base :: [Factor *]) @* (power :: Z) :: [Factor *] where ...
- type family (dims :: [Factor *]) @/ (z :: Z) :: [Factor *] where ...
- module Data.Metrology.Set
- type family DimFactorsOf dim :: [Factor *]
LCSU lookup
type family Lookup (dim :: *) (lcsu :: LCSU *) :: * where ... Source #
Lookup dim (MkLCSU_ ('(dim, unit) ': rest)) = unit | |
Lookup dim (MkLCSU_ ('(other, u) ': rest)) = Lookup dim (MkLCSU_ rest) | |
Lookup dim DefaultLCSU = DefaultUnitOfDim dim |
type family LookupList (keys :: [Factor *]) (map :: LCSU *) :: [Factor *] where ... Source #
LookupList '[] lcsu = '[] | |
LookupList (F dim z ': rest) lcsu = F (Lookup dim lcsu) z ': LookupList rest lcsu |
Validity checking
type family ConvertibleLCSUs (dfactors :: [Factor *]) (l1 :: LCSU *) (l2 :: LCSU *) :: Constraint where ... Source #
Are two LCSUs inter-convertible at the given dimension?
ConvertibleLCSUs dfactors l1 l2 = (LookupList dfactors l1 *~ LookupList dfactors l2, ValidDL dfactors l1, ValidDL dfactors l2, UnitFactor (LookupList dfactors l1), UnitFactor (LookupList dfactors l2)) |
type family ValidDLU (dfactors :: [Factor *]) (lcsu :: LCSU *) (unit :: *) where ... Source #
Check if a (dimension factors, LCSU, unit) triple are all valid to be used together.
ValidDLU dfactors lcsu unit = (dfactors ~ DimFactorsOf (DimOfUnit unit), UnitFactor (LookupList dfactors lcsu), Unit unit, UnitFactorsOf unit *~ LookupList dfactors lcsu) |
type family ValidDL (dfactors :: [Factor *]) (lcsu :: LCSU *) :: Constraint where ... Source #
Check if a (dimension factors, LCSU) pair are valid to be used together. This checks that each dimension maps to a unit of the correct dimension.
ValidDL dfactors lcsu = ValidDLU dfactors lcsu (UnitOfDimFactors dfactors lcsu) |
type family (units1 :: [Factor *]) *~ (units2 :: [Factor *]) :: Constraint where ... infix 4 Source #
Check if two [Factor *]
s, representing units, should be
considered to be equal
units1 *~ units2 = CanonicalUnitsOfFactors units1 `SetEqual` CanonicalUnitsOfFactors units2 |
type family CanonicalUnitsOfFactors (fs :: [Factor *]) :: [*] where ... Source #
Given a list of unit factors, extract out the canonical units they are based on.
CanonicalUnitsOfFactors '[] = '[] | |
CanonicalUnitsOfFactors (F u z ': fs) = CanonicalUnit u ': CanonicalUnitsOfFactors fs |
Manipulating units
type family DimOfUnitIsConsistent unit :: Constraint where ... Source #
Check to make sure that a unit has the same dimension as its base unit, if any.
type family IsCanonical (unit :: *) where ... Source #
Is this unit a canonical unit?
IsCanonical unit = BaseUnit unit == Canonical |
type CanonicalUnit (unit :: *) = CanonicalUnit' (BaseUnit unit) unit Source #
Get the canonical unit from a given unit.
For example: CanonicalUnit Foot = Meter
type family CanonicalUnit' (base_unit :: *) (unit :: *) :: * where ... Source #
Helper function in CanonicalUnit
CanonicalUnit' Canonical unit = unit | |
CanonicalUnit' base unit = CanonicalUnit' (BaseUnit base) base |
type family BaseHasConvRatio unit where ... Source #
Essentially, a constraint that checks if a conversion ratio can be
calculated for a BaseUnit
of a unit.
BaseHasConvRatio unit = HasConvRatio (IsCanonical unit) unit |
class Units units => UnitFactor (units :: [Factor *]) Source #
Classifies well-formed list of unit factors, and permits calculating a conversion ratio for the purposes of LCSU conversions.
canonicalConvRatioSpec
Instances
UnitFactor ([] :: [Factor Type]) Source # | |
Defined in Data.Metrology.Units canonicalConvRatioSpec :: Proxy [] -> Rational | |
(UnitFactor rest, Unit unit, SingI n) => UnitFactor (F unit n ': rest) Source # | |
Defined in Data.Metrology.Units canonicalConvRatioSpec :: Proxy (F unit n ': rest) -> Rational |
type family UnitFactorsOf unit :: [Factor *] Source #
The internal list of canonical units corresponding to this unit. Overriding the default should not be necessary in user code.
Instances
type UnitFactorsOf Number Source # | |
Defined in Data.Metrology.Units | |
type UnitFactorsOf (prefix :@ unit) Source # | |
Defined in Data.Metrology.Combinators type UnitFactorsOf (prefix :@ unit) = If (IsCanonical (prefix :@ unit)) (F (prefix :@ unit) One ': ([] :: [Factor Type])) (UnitFactorsOf (BaseUnit (prefix :@ unit))) | |
type UnitFactorsOf (unit :^ power) Source # | |
Defined in Data.Metrology.Combinators | |
type UnitFactorsOf (u1 :/ u2) Source # | |
Defined in Data.Metrology.Combinators | |
type UnitFactorsOf (u1 :* u2) Source # | |
Defined in Data.Metrology.Combinators |
Maniuplating dimension specifications
This will only be used at the kind level. It holds a dimension or unit with its exponent.
Instances
UnitFactor ([] :: [Factor Type]) Source # | |
Defined in Data.Metrology.Units canonicalConvRatioSpec :: Proxy [] -> Rational | |
Read n => Read (Qu ([] :: [Factor Type]) l n) Source # | |
Show n => Show (Qu ([] :: [Factor Type]) l n) Source # | |
(UnitFactor rest, Unit unit, SingI n) => UnitFactor (F unit n ': rest) Source # | |
Defined in Data.Metrology.Units canonicalConvRatioSpec :: Proxy (F unit n ': rest) -> Rational |
type family (a :: Factor *) $= (b :: Factor *) :: Bool where ... infix 4 Source #
Do these Factors represent the same dimension?
type family Extract (s :: Factor *) (lst :: [Factor *]) :: ([Factor *], Maybe (Factor *)) where ... Source #
(Extract s lst)
pulls the Factor that matches s out of lst, returning a
diminished list and, possibly, the extracted Factor.
Extract A [A, B, C] ==> ([B, C], Just A Extract F [A, B, C] ==> ([A, B, C], Nothing)
type family Reorder (a :: [Factor *]) (b :: [Factor *]) :: [Factor *] where ... Source #
Reorders a to be the in the same order as b, putting entries not in b at the end
Reorder [A 1, B 2] [B 5, A 2] ==> [B 2, A 1] Reorder [A 1, B 2, C 3] [C 2, A 8] ==> [C 3, A 1, B 2] Reorder [A 1, B 2] [B 4, C 1, A 9] ==> [B 2, A 1] Reorder x x ==> x Reorder x [] ==> x Reorder [] x ==> []
type family Reorder' (scrut :: ([Factor *], Maybe (Factor *))) (t :: [Factor *]) :: [Factor *] where ... Source #
Helper function in Reorder
type family (a :: [Factor *]) @~ (b :: [Factor *]) :: Constraint where ... infix 4 Source #
Check if two [Factor *]
s should be considered to be equal
type family Normalize (d :: [Factor *]) :: [Factor *] where ... Source #
Take a [Factor *]
and remove any Factor
s with an exponent of 0
type family (a :: [Factor *]) @@+ (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #
Adds corresponding exponents in two dimension, assuming the lists are ordered similarly.
type family (a :: [Factor *]) @+ (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #
Adds corresponding exponents in two dimension, preserving order
type family (a :: [Factor *]) @@- (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #
Subtract exponents in two dimensions, assuming the lists are ordered similarly.
type family (a :: [Factor *]) @- (b :: [Factor *]) :: [Factor *] where ... infixl 6 Source #
Subtract exponents in two dimensions
type family (base :: [Factor *]) @* (power :: Z) :: [Factor *] where ... infixl 7 Source #
Multiplication of the exponents in a dimension by a scalar
type family (dims :: [Factor *]) @/ (z :: Z) :: [Factor *] where ... infixl 7 Source #
Division of the exponents in a dimension by a scalar
Set operations on lists
module Data.Metrology.Set
Dimensions
type family DimFactorsOf dim :: [Factor *] Source #
Retrieve a list of Factor
s representing the given dimension. Overriding
the default of this type family should not be necessary in user code.
Instances
type DimFactorsOf Dimensionless Source # | |
Defined in Data.Metrology.Units | |
type DimFactorsOf (dim :^ power) Source # | |
Defined in Data.Metrology.Combinators | |
type DimFactorsOf (d1 :/ d2) Source # | |
Defined in Data.Metrology.Combinators | |
type DimFactorsOf (d1 :* d2) Source # | |
Defined in Data.Metrology.Combinators |