type-natural-0.2.3.2: Type-level natural and proofs of their properties.

Safe HaskellNone
LanguageHaskell98

Data.Type.Natural

Contents

Description

Type level peano natural number, some arithmetic functions and their singletons.

Synopsis

Re-exported modules.

Natural Numbers

Peano natural numbers. It will be promoted to the type-level natural number.

data Nat Source

Constructors

Z 
S Nat 

Instances

Eq Nat 
Num Nat 
Ord Nat 
Show Nat 
Typeable Nat Z 
SingI Nat Z 
Preorder Nat Leq 
SingKind Nat (KProxy Nat) 
SingI Nat n0 => SingI Nat (S n) 
Monomorphicable Nat (Sing Nat) 
POrd Nat (KProxy Nat) 
SEq Nat (KProxy Nat) 
PEq Nat (KProxy Nat) 
SDecide Nat (KProxy Nat) 
Eq (Sing Nat n) 
Show (Sing Nat n) 
Typeable (Nat -> *) Ordinal 
Typeable (Nat -> Nat) S 
SuppressUnusedWarnings (Nat -> TyFun Nat Bool -> *) (:<<=$$) 
SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) MinSym1 
SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) MaxSym1 
SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) (:*$$) 
SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) (:+$$) 
SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) (:-$$) 
SuppressUnusedWarnings (TyFun Nat (TyFun Nat Bool -> *) -> *) (:<<=$) 
SuppressUnusedWarnings (TyFun Nat (TyFun Nat Nat -> *) -> *) MinSym0 
SuppressUnusedWarnings (TyFun Nat (TyFun Nat Nat -> *) -> *) MaxSym0 
SuppressUnusedWarnings (TyFun Nat (TyFun Nat Nat -> *) -> *) (:*$) 
SuppressUnusedWarnings (TyFun Nat (TyFun Nat Nat -> *) -> *) (:+$) 
SuppressUnusedWarnings (TyFun Nat (TyFun Nat Nat -> *) -> *) (:-$) 
SuppressUnusedWarnings (TyFun Nat Nat -> *) SSym0 
data Sing Nat where 
type Compare Nat Z Z = EQ 
type (:==) Nat a0 b0 
type Apply Nat Nat SSym0 l0 = SSym1 l0 
type Compare Nat Z (S rhs0) = LT 
type Apply Bool Nat ((:<<=$$) l1) l0 = (:<<=$$$) l1 l0 
type Apply Nat Nat (MinSym1 l1) l0 = MinSym2 l1 l0 
type Apply Nat Nat (MaxSym1 l1) l0 = MaxSym2 l1 l0 
type Apply Nat Nat ((:*$$) l1) l0 = (:*$$$) l1 l0 
type Apply Nat Nat ((:+$$) l1) l0 = (:+$$$) l1 l0 
type Apply Nat Nat ((:-$$) l1) l0 = (:-$$$) l1 l0 
type DemoteRep Nat (KProxy Nat) = Nat 
type MonomorphicRep Nat (Sing Nat) = Int 
type Compare Nat (S lhs0) Z = GT 
type Compare Nat (S lhs0) (S rhs0) = ThenCmp EQ (Compare Nat lhs0 rhs0) 
type Apply (TyFun Nat Bool -> *) Nat (:<<=$) l0 = (:<<=$$) l0 
type Apply (TyFun Nat Nat -> *) Nat MinSym0 l0 = MinSym1 l0 
type Apply (TyFun Nat Nat -> *) Nat MaxSym0 l0 = MaxSym1 l0 
type Apply (TyFun Nat Nat -> *) Nat (:*$) l0 = (:*$$) l0 
type Apply (TyFun Nat Nat -> *) Nat (:+$) l0 = (:+$$) l0 
type Apply (TyFun Nat Nat -> *) Nat (:-$) l0 = (:-$$) l0 

data SSym0 l Source

Instances

type SSym1 t = S t Source

type ZSym0 = Z Source

Singleton type for Nat.

type SNat z = Sing z Source

data family Sing a

The singleton kind-indexed data family.

Instances

SDecide k (KProxy k) => TestEquality k (Sing k) 
Monomorphicable Nat (Sing Nat) 
Eq (Sing Nat n) 
Show (Sing Nat n) 
data Sing Bool where 
data Sing Ordering where 
data Sing Nat where 
data Sing Symbol where 
data Sing () where 
data Sing Nat where 
type MonomorphicRep Nat (Sing Nat) = Int 
data Sing [a0] where 
data Sing (Maybe a0) where 
data Sing (TyFun k1 k2 -> *) = SLambda {} 
data Sing (Either a0 b0) where 
data Sing ((,) a0 b0) where 
data Sing ((,,) a0 b0 c0) where 
data Sing ((,,,) a0 b0 c0 d0) where 
data Sing ((,,,,) a0 b0 c0 d0 e0) where 
data Sing ((,,,,,) a0 b0 c0 d0 e0 f0) where 
data Sing ((,,,,,,) a0 b0 c0 d0 e0 f0 g0) where 

Smart constructors

WARNING: Smart constructors are deprecated as of singletons 0.10, so these are provided only for backward compatibility.

sZ :: SNat Z Source

Deprecated: Smart constructors are no longer needed in singletons; Use SS or SZ instead.

sS :: SNat n -> SNat (S n) Source

Deprecated: Smart constructors are no longer needed in singletons; Use SS or SZ instead.

Arithmetic functions and their singletons.

min :: Nat -> Nat -> Nat Source

type family Min a a :: Nat Source

Equations

Min Z Z = ZSym0 
Min Z (S z) = ZSym0 
Min (S z) Z = ZSym0 
Min (S m) (S n) = Apply SSym0 (Apply (Apply MinSym0 m) n) 

sMin :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply MinSym0 t) t) Source

max :: Nat -> Nat -> Nat Source

type family Max a a :: Nat Source

Equations

Max Z Z = ZSym0 
Max Z (S n) = Apply SSym0 n 
Max (S n) Z = Apply SSym0 n 
Max (S n) (S m) = Apply SSym0 (Apply (Apply MaxSym0 n) m) 

sMax :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply MaxSym0 t) t) Source

data MinSym0 l Source

Instances

data MinSym1 l l Source

Instances

type MinSym2 t t = Min t t Source

data MaxSym0 l Source

Instances

data MaxSym1 l l Source

Instances

type MaxSym2 t t = Max t t Source

type (:+:) n m = n :+ m infixl 6 Source

type family a :+ a :: Nat infixl 6 Source

Equations

Z :+ n = n 
(S m) :+ n = Apply SSym0 (Apply (Apply (:+$) m) n) 

data (:+$) l Source

Instances

data l :+$$ l Source

Instances

SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) (:+$$) 
type Apply Nat Nat ((:+$$) l1) l0 = (:+$$$) l1 l0 

type (:+$$$) t t = (:+) t t Source

(%+) :: SNat n -> SNat m -> SNat (n :+: m) infixl 6 Source

Addition for singleton numbers.

(%:+) :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply (:+$) t) t) infixl 6 Source

type family a :* a :: Nat infixl 7 Source

Equations

Z :* z = ZSym0 
(S n) :* m = Apply (Apply (:+$) (Apply (Apply (:*$) n) m)) m 

type (:*:) n m = n :* m infixl 7 Source

Type-level multiplication.

data (:*$) l Source

Instances

data l :*$$ l Source

Instances

SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) (:*$$) 
type Apply Nat Nat ((:*$$) l1) l0 = (:*$$$) l1 l0 

type (:*$$$) t t = (:*) t t Source

(%:*) :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply (:*$) t) t) infixl 7 Source

(%*) :: SNat n -> SNat m -> SNat (n :*: m) infixl 7 Source

Multiplication for singleton numbers.

type (:-:) n m = n :- m infixl 6 Source

type family a :- a :: Nat Source

Equations

n :- Z = n 
(S n) :- (S m) = Apply (Apply (:-$) n) m 
Z :- (S z) = ZSym0 

type (:**:) n m = n :** m Source

Type-level exponentiation.

type family a :** a :: Nat Source

Equations

n :** Z = Apply SSym0 ZSym0 
n :** (S m) = Apply (Apply (:*$) (Apply (Apply (:**$) n) m)) n 

(%:**) :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply (:**$) t) t) Source

(%**) :: SNat n -> SNat m -> SNat (n :**: m) Source

Exponentiation for singleton numbers.

data (:-$) l Source

Instances

data l :-$$ l Source

Instances

SuppressUnusedWarnings (Nat -> TyFun Nat Nat -> *) (:-$$) 
type Apply Nat Nat ((:-$$) l1) l0 = (:-$$$) l1 l0 

type (:-$$$) t t = (:-) t t Source

(%:-) :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply (:-$) t) t) infixl 6 Source

(%-) :: ((m :<<= n) ~ True) => SNat n -> SNat m -> SNat (n :-: m) infixl 6 Source

Type-level predicate & judgements

data Leq n m where Source

Comparison via GADTs.

Constructors

ZeroLeq :: SNat m -> Leq Zero m 
SuccLeqSucc :: Leq n m -> Leq (S n) (S m) 

Instances

class n :<= m Source

Comparison via type-class.

Instances

Z :<= n 
(:<=) n m => (S n) :<= (S m) 

type family a :<<= a :: Bool Source

Boolean-valued type-level comparison function.

Equations

Z :<<= z = TrueSym0 
(S z) :<<= Z = FalseSym0 
(S n) :<<= (S m) = Apply (Apply (:<<=$) n) m 

data (:<<=$) l Source

Instances

data l :<<=$$ l Source

Instances

type (:<<=$$$) t t = (:<<=) t t Source

(%:<<=) :: forall t t. Sing t -> Sing t -> Sing (Apply (Apply (:<<=$) t) t) Source

type LeqInstance n m = Dict (n :<= m) Source

boolToPropLeq :: ((n :<<= m) ~ True) => SNat n -> SNat m -> Leq n m Source

boolToClassLeq :: ((n :<<= m) ~ True) => SNat n -> SNat m -> LeqInstance n m Source

type LeqTrueInstance a b = Dict ((a :<<= b) ~ True) Source

propToBoolLeq :: forall n m. Leq n m -> LeqTrueInstance n m Source

Conversion functions

natToInt :: Integral n => Nat -> n Source

Convert Nat into normal integers.

intToNat :: (Integral a, Ord a) => a -> Nat Source

Convert integral numbers into Nat

sNatToInt :: Num n => SNat x -> n Source

Convert 'SNat n' into normal integers.

Quasi quotes for natural numbers

nat :: QuasiQuoter Source

Quotesi-quoter for Nat. This can be used for an expression, pattern and type.

for example: sing :: SNat ([nat| 2 |] :+ [nat| 5 |])

snat :: QuasiQuoter Source

Quotesi-quoter for SNat. This can be used for an expression, pattern and type.

For example: [snat|12|] %+ [snat| 5 |], sing :: [snat| 12 |], f [snat| 12 |] = "hey"

Properties of natural numbers

succCongEq :: (n :=: m) -> S n :=: S m Source

plusCongR :: SNat n -> (m :=: m') -> (m :+ n) :=: (m' :+ n) Source

plusCongL :: SNat n -> (m :=: m') -> (n :+ m) :=: (n :+ m') Source

succPlusL :: SNat n -> SNat m -> (S n :+ m) :=: S (n :+ m) Source

succPlusR :: SNat n -> SNat m -> (n :+ S m) :=: S (n :+ m) Source

plusZR :: SNat n -> (n :+: Z) :=: n Source

plusZL :: SNat n -> (Z :+: n) :=: n Source

eqPreservesS :: (n :=: m) -> S n :=: S m Source

plusAssociative :: SNat n -> SNat m -> SNat l -> (n :+: (m :+: l)) :=: ((n :+: m) :+: l) Source

multAssociative :: SNat n -> SNat m -> SNat l -> (n :* (m :* l)) :=: ((n :* m) :* l) Source

multComm :: SNat n -> SNat m -> (n :* m) :=: (m :* n) Source

multOneL :: SNat n -> (One :* n) :=: n Source

multOneR :: SNat n -> (n :* One) :=: n Source

snEqZAbsurd :: (S n :=: Z) -> a Source

succInjective :: (S n :=: S m) -> n :=: m Source

plusInjectiveL :: SNat n -> SNat m -> SNat l -> ((n :+ m) :=: (n :+ l)) -> m :=: l Source

plusInjectiveR :: SNat n -> SNat m -> SNat l -> ((n :+ l) :=: (m :+ l)) -> n :=: m Source

plusMultDistr :: SNat n -> SNat m -> SNat l -> ((n :+ m) :* l) :=: ((n :* l) :+ (m :* l)) Source

multPlusDistr :: SNat n -> SNat m -> SNat l -> (n :* (m :+ l)) :=: ((n :* m) :+ (n :* l)) Source

multCongL :: SNat n -> (m :=: l) -> (n :* m) :=: (n :* l) Source

multCongR :: SNat n -> (m :=: l) -> (m :* n) :=: (l :* n) Source

plusCommutative :: SNat n -> SNat m -> (n :+: m) :=: (m :+: n) Source

minusCongEq :: (n :=: m) -> SNat l -> (n :-: l) :=: (m :-: l) Source

eqSuccMinus :: ((m :<<= n) ~ True) => SNat n -> SNat m -> (S n :-: m) :=: S (n :-: m) Source

plusMinusEqL :: SNat n -> SNat m -> ((n :+: m) :-: m) :=: n Source

plusMinusEqR :: SNat n -> SNat m -> ((m :+: n) :-: m) :=: n Source

plusSR :: SNat n -> SNat m -> S (n :+: m) :=: (n :+: S m) Source

plusNeutralR :: SNat n -> SNat m -> ((n :+ m) :=: n) -> m :=: Z Source

plusNeutralL :: SNat n -> SNat m -> ((n :+ m) :=: m) -> n :=: Z Source

leqRhs :: Leq n m -> SNat m Source

leqLhs :: Leq n m -> SNat n Source

minComm :: SNat n -> SNat m -> Min n m :=: Min m n Source

maxZL :: SNat n -> Max Z n :=: n Source

maxComm :: SNat n -> SNat m -> Max n m :=: Max m n Source

maxZR :: SNat n -> Max n Z :=: n Source

Properties of ordering Leq

leqRefl :: SNat n -> Leq n n Source

leqSucc :: SNat n -> Leq n (S n) Source

leqTrans :: Leq n m -> Leq m l -> Leq n l Source

plusMonotone :: Leq n m -> Leq l k -> Leq (n :+: l) (m :+: k) Source

plusLeqL :: SNat n -> SNat m -> Leq n (n :+: m) Source

plusLeqR :: SNat n -> SNat m -> Leq m (n :+: m) Source

minLeqL :: SNat n -> SNat m -> Leq (Min n m) n Source

minLeqR :: SNat n -> SNat m -> Leq (Min n m) m Source

leqAnitsymmetric :: Leq n m -> Leq m n -> n :=: m Source

maxLeqL :: SNat n -> SNat m -> Leq n (Max n m) Source

maxLeqR :: SNat n -> SNat m -> Leq m (Max n m) Source

leqSnZAbsurd :: Leq (S n) Z -> a Source

leqSnLeq :: Leq (S n) m -> Leq n m Source

leqPred :: Leq (S n) (S m) -> Leq n m Source

leqSnnAbsurd :: Leq (S n) n -> a Source

Useful type synonyms and constructors

type Zero = (ZSym0 :: Nat) Source

type N0 = (ZeroSym0 :: Nat) Source

type N1 = (OneSym0 :: Nat) Source

type N2 = (TwoSym0 :: Nat) Source

type N3 = (ThreeSym0 :: Nat) Source

type N4 = (FourSym0 :: Nat) Source

type N5 = (FiveSym0 :: Nat) Source

type N6 = (SixSym0 :: Nat) Source

type N7 = (SevenSym0 :: Nat) Source

type N8 = (EightSym0 :: Nat) Source

type N9 = (NineSym0 :: Nat) Source

type N10 = (TenSym0 :: Nat) Source

type N11 = (ElevenSym0 :: Nat) Source

type N12 = (TwelveSym0 :: Nat) Source

type N20 = (TwentySym0 :: Nat) Source