units-2.4.1: A domain-specific type system for dimensional analysis

Copyright(C) 2013 Richard Eisenberg
LicenseBSD-style (see LICENSE)
MaintainerRichard Eisenberg (rae@cs.brynmawr.edu)
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Metrology.Z

Contents

Description

This module defines a datatype and operations to represent type-level integers. Though it's defined as part of the units package, it may be useful beyond dimensional analysis. If you have a compelling non-units use of this package, please let me (Richard, rae at cs.brynmawr.edu) know.

Synopsis

The Z datatype

data Z Source #

The datatype for type-level integers.

Constructors

Zero 
S Z 
P Z 

Instances

Eq Z Source # 

Methods

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

(/=) :: Z -> Z -> Bool #

SEq Z Source # 

Methods

(%:==) :: Sing Z a -> Sing Z b -> Sing Bool ((Z :== a) b) #

(%:/=) :: Sing Z a -> Sing Z b -> Sing Bool ((Z :/= a) b) #

PEq Z Source # 

Associated Types

type (Z :== (x :: Z)) (y :: Z) :: Bool #

type (Z :/= (x :: Z)) (y :: Z) :: Bool #

SDecide Z Source # 

Methods

(%~) :: Sing Z a -> Sing Z b -> Decision ((Z :~: a) b) #

SingKind Z Source # 

Associated Types

type Demote Z = (r :: *) #

Methods

fromSing :: Sing Z a -> Demote Z #

toSing :: Demote Z -> SomeSing Z #

SingI Z Zero Source # 

Methods

sing :: Sing Zero a #

SingI Z n => SingI Z (S n) Source # 

Methods

sing :: Sing (S n) a #

SingI Z n => SingI Z (P n) Source # 

Methods

sing :: Sing (P n) a #

SuppressUnusedWarnings (TyFun Z Z -> *) PSym0 Source # 
SuppressUnusedWarnings (TyFun Z Z -> *) SSym0 Source # 
data Sing Z Source # 
data Sing Z where
type Demote Z Source # 
type Demote Z = Z
type (:/=) Z x y Source # 
type (:/=) Z x y = Not ((:==) Z x y)
type (:==) Z a b Source # 
type (:==) Z a b
type Apply Z Z PSym0 l Source # 
type Apply Z Z PSym0 l = P l
type Apply Z Z SSym0 l Source # 
type Apply Z Z SSym0 l = S l

data family Sing k (a :: k) :: * #

The singleton kind-indexed data family.

Instances

data Sing Bool 
data Sing Bool where
data Sing Ordering 
data Sing Nat 
data Sing Nat where
data Sing Symbol 
data Sing Symbol where
data Sing () 
data Sing () where
data Sing Z # 
data Sing Z where
data Sing [a] 
data Sing [a] where
data Sing (Maybe a) 
data Sing (Maybe a) where
data Sing (NonEmpty a) 
data Sing (NonEmpty a) where
data Sing (Either a b) 
data Sing (Either a b) where
data Sing (a, b) 
data Sing (a, b) where
data Sing ((~>) k1 k2) 
data Sing ((~>) k1 k2) = SLambda {}
data Sing (a, b, c) 
data Sing (a, b, c) where
data Sing (a, b, c, d) 
data Sing (a, b, c, d) where
data Sing (a, b, c, d, e) 
data Sing (a, b, c, d, e) where
data Sing (a, b, c, d, e, f) 
data Sing (a, b, c, d, e, f) where
data Sing (a, b, c, d, e, f, g) 
data Sing (a, b, c, d, e, f, g) where

type SZ = (Sing :: Z -> Type) Source #

Defunctionalization symbols (these can be ignored)

data SSym0 (l :: TyFun Z Z) Source #

Instances

type SSym1 (t :: Z) = S t Source #

data PSym0 (l :: TyFun Z Z) Source #

Instances

type PSym1 (t :: Z) = P t Source #

Conversions

zToInt :: Z -> Int Source #

Convert a Z to an Int

szToInt :: Sing (z :: Z) -> Int Source #

Convert a singleton Z to an Int.

Type-level operations

Arithmetic

type family Succ (z :: Z) :: Z where ... Source #

Add one to an integer

Equations

Succ Zero = S Zero 
Succ (P z) = z 
Succ (S z) = S (S z) 

type family Pred (z :: Z) :: Z where ... Source #

Subtract one from an integer

Equations

Pred Zero = P Zero 
Pred (P z) = P (P z) 
Pred (S z) = z 

type family Negate (z :: Z) :: Z where ... Source #

Negate an integer

Equations

Negate Zero = Zero 
Negate (S z) = P (Negate z) 
Negate (P z) = S (Negate z) 

type family (a :: Z) #+ (b :: Z) :: Z where ... infixl 6 Source #

Add two integers

Equations

Zero #+ z = z 
(S z1) #+ (S z2) = S (S (z1 #+ z2)) 
(S z1) #+ Zero = S z1 
(S z1) #+ (P z2) = z1 #+ z2 
(P z1) #+ (S z2) = z1 #+ z2 
(P z1) #+ Zero = P z1 
(P z1) #+ (P z2) = P (P (z1 #+ z2)) 

type family (a :: Z) #- (b :: Z) :: Z where ... infixl 6 Source #

Subtract two integers

Equations

z #- Zero = z 
(S z1) #- (S z2) = z1 #- z2 
Zero #- (S z2) = P (Zero #- z2) 
(P z1) #- (S z2) = P (P (z1 #- z2)) 
(S z1) #- (P z2) = S (S (z1 #- z2)) 
Zero #- (P z2) = S (Zero #- z2) 
(P z1) #- (P z2) = z1 #- z2 

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

Multiply two integers

Equations

Zero #* z = Zero 
(S z1) #* z2 = (z1 #* z2) #+ z2 
(P z1) #* z2 = (z1 #* z2) #- z2 

type family (a :: Z) #/ (b :: Z) :: Z where ... Source #

Divide two integers

Equations

Zero #/ b = Zero 
a #/ (P b') = Negate (a #/ Negate (P b')) 
a #/ b = ZDiv b b a 

sSucc :: Sing z -> Sing (Succ z) Source #

Add one to a singleton Z.

sPred :: Sing z -> Sing (Pred z) Source #

Subtract one from a singleton Z.

sNegate :: Sing z -> Sing (Negate z) Source #

Negate a singleton Z.

Comparisons

type family (a :: Z) < (b :: Z) :: Bool where ... Source #

Less-than comparison

Equations

Zero < Zero = False 
Zero < (S n) = True 
Zero < (P n) = False 
(S n) < Zero = False 
(S n) < (S n') = n < n' 
(S n) < (P n') = False 
(P n) < Zero = True 
(P n) < (S n') = True 
(P n) < (P n') = n < n' 

type family NonNegative z :: Constraint where ... Source #

Check if a type-level integer is in fact a natural number

Equations

NonNegative Zero = () 
NonNegative (S z) = () 

Synonyms for certain numbers

type One = S Zero Source #

type Two = S One Source #

type Three = S Two Source #

type Five = S Four Source #

type MOne = P Zero Source #

type MTwo = P MOne Source #

sZero :: Sing Z Zero Source #

This is the singleton value representing Zero at the term level and at the type level, simultaneously. Used for raising units to powers.

sThree :: Sing Z (S (S (S Zero))) Source #

sFour :: Sing Z (S (S (S (S Zero)))) Source #

sFive :: Sing Z (S (S (S (S (S Zero))))) Source #

sMFour :: Sing Z (P (P (P (P Zero)))) Source #

sMFive :: Sing Z (P (P (P (P (P Zero))))) Source #

Deprecated synonyms

pZero :: Sing Z Zero Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pOne :: Sing Z (S Zero) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pTwo :: Sing Z (S (S Zero)) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pThree :: Sing Z (S (S (S Zero))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pFour :: Sing Z (S (S (S (S Zero)))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pFive :: Sing Z (S (S (S (S (S Zero))))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMOne :: Sing Z (P Zero) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMTwo :: Sing Z (P (P Zero)) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMThree :: Sing Z (P (P (P Zero))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMFour :: Sing Z (P (P (P (P Zero)))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pMFive :: Sing Z (P (P (P (P (P Zero))))) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pSucc :: Sing Z z -> Sing Z (Succ z) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.

pPred :: Sing Z z -> Sing Z (Pred z) Source #

Deprecated: The singleton prefix is changing from p to s. The p versions will be removed in a future release.