Copyright | (C) 2013 Richard Eisenberg |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | Richard Eisenberg (eir@cis.upenn.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.
- type family Lookup dim lcsu :: *
- type family LookupList keys map :: [Factor *]
- type family ConvertibleLCSUs dfactors l1 l2 :: Constraint
- type family ValidDLU dfactors lcsu unit
- type family ValidDL dfactors lcsu :: Constraint
- type family units1 *~ units2 :: Constraint
- type family CanonicalUnitsOfFactors fs :: [*]
- type family DimOfUnitIsConsistent unit :: Constraint
- type family IsCanonical unit
- type CanonicalUnit unit = CanonicalUnit' (BaseUnit unit) unit
- type family CanonicalUnit' base_unit unit :: *
- type family BaseHasConvRatio unit
- class UnitFactor units
- data Factor star = F star Z
- type family a $= b :: Bool
- type family Extract s lst :: ([Factor *], Maybe (Factor *))
- type family Reorder a b :: [Factor *]
- type family Reorder' scrut t :: [Factor *]
- type family a @~ b :: Constraint
- type family Normalize d :: [Factor *]
- type family a @@+ b :: [Factor *]
- type family a @+ b :: [Factor *]
- type family a @@- b :: [Factor *]
- type family a @- b :: [Factor *]
- type family NegDim a :: Factor *
- type family NegList a :: [Factor *]
- type family base @* power :: [Factor *]
- type family dims @/ z :: [Factor *]
- module Data.Metrology.Set
LCSU lookup
type family Lookup dim lcsu :: * 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 map :: [Factor *] Source
LookupList [] lcsu = [] | |
LookupList (F dim z : rest) lcsu = F (Lookup dim lcsu) z : LookupList rest lcsu |
Validity checking
type family ConvertibleLCSUs dfactors l1 l2 :: Constraint 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 lcsu unit 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 lcsu :: Constraint 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 *~ units2 :: Constraint 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 :: [*] 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 Source
Check to make sure that a unit has the same dimension as its base unit, if any.
type family IsCanonical unit 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 :: * Source
Helper function in CanonicalUnit
CanonicalUnit' Canonical unit = unit | |
CanonicalUnit' base unit = CanonicalUnit' (BaseUnit base) base |
type family BaseHasConvRatio unit 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 UnitFactor units Source
Classifies well-formed list of unit factors, and permits calculating a conversion ratio for the purposes of LCSU conversions.
canonicalConvRatioSpec
UnitFactor ([] (Factor *)) | |
(UnitFactor rest, Unit unit, SingI Z n) => UnitFactor ((:) (Factor *) (F * unit n) rest) |
Maniuplating dimension specifications
This will only be used at the kind level. It holds a dimension or unit with its exponent.
UnitFactor ([] (Factor *)) | |
(UnitFactor rest, Unit unit, SingI Z n) => UnitFactor ((:) (Factor *) (F * unit n) rest) |
type family Extract s lst :: ([Factor *], Maybe (Factor *)) 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 b :: [Factor *] 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 a @~ b :: Constraint infix 4 Source
Check if two [Factor *]
s should be considered to be equal
type family Normalize d :: [Factor *] Source
Take a [Factor *]
and remove any Factor
s with an exponent of 0
type family a @@+ b :: [Factor *] infixl 6 Source
Adds corresponding exponents in two dimension, assuming the lists are ordered similarly.
type family a @+ b :: [Factor *] infixl 6 Source
Adds corresponding exponents in two dimension, preserving order
type family a @@- b :: [Factor *] infixl 6 Source
Subtract exponents in two dimensions, assuming the lists are ordered similarly.
type family base @* power :: [Factor *] infixl 7 Source
Multiplication of the exponents in a dimension by a scalar
type family dims @/ z :: [Factor *] infixl 7 Source
Division of the exponents in a dimension by a scalar
Set operations on lists
module Data.Metrology.Set