bin-0.1.3: Bin: binary natural numbers.
Safe HaskellSafe
LanguageHaskell2010

Data.Type.Bin

Description

Binary natural numbers. DataKinds stuff.

Synopsis

Singleton

data SBin (b :: Bin) where Source #

Singleton of Bin.

Constructors

SBZ :: SBin 'BZ 
SBP :: SBinPI b => SBin ('BP b) 

Instances

Instances details
TestEquality SBin Source # 
Instance details

Defined in Data.Type.Bin

Methods

testEquality :: forall (a :: k) (b :: k). SBin a -> SBin b -> Maybe (a :~: b) #

EqP SBin Source #

Since: 0.1.3

Instance details

Defined in Data.Type.Bin

Methods

eqp :: forall (a :: k) (b :: k). SBin a -> SBin b -> Bool #

GNFData SBin Source #

Since: 0.1.2

Instance details

Defined in Data.Type.Bin

Methods

grnf :: forall (a :: k). SBin a -> () #

GEq SBin Source #

Since: 0.1.2

Instance details

Defined in Data.Type.Bin

Methods

geq :: forall (a :: k) (b :: k). SBin a -> SBin b -> Maybe (a :~: b) #

GShow SBin Source #

Since: 0.1.2

Instance details

Defined in Data.Type.Bin

Methods

gshowsPrec :: forall (a :: k). Int -> SBin a -> ShowS #

Show (SBin b) Source # 
Instance details

Defined in Data.Type.Bin

Methods

showsPrec :: Int -> SBin b -> ShowS #

show :: SBin b -> String #

showList :: [SBin b] -> ShowS #

SBinI b => Boring (SBin b) Source #

Since: 0.1.2

Instance details

Defined in Data.Type.Bin

Methods

boring :: SBin b #

NFData (SBin n) Source #

Since: 0.1.2

Instance details

Defined in Data.Type.Bin

Methods

rnf :: SBin n -> () #

Eq (SBin a) Source #

Since: 0.1.3

Instance details

Defined in Data.Type.Bin

Methods

(==) :: SBin a -> SBin a -> Bool #

(/=) :: SBin a -> SBin a -> Bool #

Ord (SBin a) Source #

Since: 0.1.3

Instance details

Defined in Data.Type.Bin

Methods

compare :: SBin a -> SBin a -> Ordering #

(<) :: SBin a -> SBin a -> Bool #

(<=) :: SBin a -> SBin a -> Bool #

(>) :: SBin a -> SBin a -> Bool #

(>=) :: SBin a -> SBin a -> Bool #

max :: SBin a -> SBin a -> SBin a #

min :: SBin a -> SBin a -> SBin a #

data SBinP (b :: BinP) where Source #

Singleton of BinP.

Constructors

SBE :: SBinP 'BE 
SB0 :: SBinPI b => SBinP ('B0 b) 
SB1 :: SBinPI b => SBinP ('B1 b) 

Instances

Instances details
TestEquality SBinP Source # 
Instance details

Defined in Data.Type.BinP

Methods

testEquality :: forall (a :: k) (b :: k). SBinP a -> SBinP b -> Maybe (a :~: b) #

EqP SBinP Source #

Since: 0.1.3

Instance details

Defined in Data.Type.BinP

Methods

eqp :: forall (a :: k) (b :: k). SBinP a -> SBinP b -> Bool #

GNFData SBinP Source #

Since: 0.1.2

Instance details

Defined in Data.Type.BinP

Methods

grnf :: forall (a :: k). SBinP a -> () #

GEq SBinP Source #

Since: 0.1.2

Instance details

Defined in Data.Type.BinP

Methods

geq :: forall (a :: k) (b :: k). SBinP a -> SBinP b -> Maybe (a :~: b) #

GShow SBinP Source #

Since: 0.1.2

Instance details

Defined in Data.Type.BinP

Methods

gshowsPrec :: forall (a :: k). Int -> SBinP a -> ShowS #

Show (SBinP b) Source # 
Instance details

Defined in Data.Type.BinP

Methods

showsPrec :: Int -> SBinP b -> ShowS #

show :: SBinP b -> String #

showList :: [SBinP b] -> ShowS #

SBinPI b => Boring (SBinP b) Source #

Since: 0.1.2

Instance details

Defined in Data.Type.BinP

Methods

boring :: SBinP b #

NFData (SBinP n) Source #

Since: 0.1.2

Instance details

Defined in Data.Type.BinP

Methods

rnf :: SBinP n -> () #

Eq (SBinP a) Source #

Since: 0.1.3

Instance details

Defined in Data.Type.BinP

Methods

(==) :: SBinP a -> SBinP a -> Bool #

(/=) :: SBinP a -> SBinP a -> Bool #

Ord (SBinP a) Source #

Since: 0.1.3

Instance details

Defined in Data.Type.BinP

Methods

compare :: SBinP a -> SBinP a -> Ordering #

(<) :: SBinP a -> SBinP a -> Bool #

(<=) :: SBinP a -> SBinP a -> Bool #

(>) :: SBinP a -> SBinP a -> Bool #

(>=) :: SBinP a -> SBinP a -> Bool #

max :: SBinP a -> SBinP a -> SBinP a #

min :: SBinP a -> SBinP a -> SBinP a #

sbinToBin :: forall n. SBin n -> Bin Source #

Convert SBin to Bin.

sbinpToBinP :: forall n. SBinP n -> BinP Source #

Cconvert SBinP to BinP.

sbinToNatural :: forall n. SBin n -> Natural Source #

Convert SBin to Natural.

>>> sbinToNatural (sbin :: SBin Bin9)
9

sbinpToNatural :: forall n. SBinP n -> Natural Source #

Convert SBinP to Natural.

>>> sbinpToNatural (sbinp :: SBinP BinP8)
8

Implicit

class SBinI (b :: Bin) where Source #

Let constraint solver construct SBin.

Methods

sbin :: SBin b Source #

Instances

Instances details
SBinI 'BZ Source # 
Instance details

Defined in Data.Type.Bin

Methods

sbin :: SBin 'BZ Source #

SBinPI b => SBinI ('BP b) Source # 
Instance details

Defined in Data.Type.Bin

Methods

sbin :: SBin ('BP b) Source #

class SBinPI (b :: BinP) where Source #

Let constraint solver construct SBinP.

Methods

sbinp :: SBinP b Source #

Instances

Instances details
SBinPI 'BE Source # 
Instance details

Defined in Data.Type.BinP

Methods

sbinp :: SBinP 'BE Source #

SBinPI b => SBinPI ('B0 b) Source # 
Instance details

Defined in Data.Type.BinP

Methods

sbinp :: SBinP ('B0 b) Source #

SBinPI b => SBinPI ('B1 b) Source # 
Instance details

Defined in Data.Type.BinP

Methods

sbinp :: SBinP ('B1 b) Source #

withSBin :: SBin b -> (SBinI b => r) -> r Source #

Construct SBinI dictionary from SBin.

withSBinP :: SBinP b -> (SBinPI b => r) -> r Source #

Construct SBinPI dictionary from SBinP.

reify :: forall r. Bin -> (forall b. SBinI b => Proxy b -> r) -> r Source #

Reify Bin

>>> reify bin3 reflect
3

reflect :: forall b proxy. SBinI b => proxy b -> Bin Source #

Reflect type-level Bin to the term level.

reflectToNum :: forall b proxy a. (SBinI b, Num a) => proxy b -> a Source #

Reflect type-level Bin to the term level Num.

Type equality

eqBin :: forall a b. (SBinI a, SBinI b) => Maybe (a :~: b) Source #

type family EqBin (n :: Bin) (m :: Bin) where ... Source #

Since: 0.1.2

Equations

EqBin 'BZ 'BZ = 'True 
EqBin ('BP n) ('BP m) = EqBinP n m 
EqBin n m = 'False 

Induction

induction Source #

Arguments

:: forall b f. SBinI b 
=> f 'BZ

\(P(0)\)

-> f ('BP 'BE)

\(P(1)\)

-> (forall bb. SBinPI bb => f ('BP bb) -> f ('BP ('B0 bb)))

\(\forall b. P(b) \to P(2b)\)

-> (forall bb. SBinPI bb => f ('BP bb) -> f ('BP ('B1 bb)))

\(\forall b. P(b) \to P(2b + 1)\)

-> f b 

Induction on Bin.

Arithmetic

Successor

type Succ b = 'BP (Succ' b) Source #

Successor type family.

>>> :kind! Succ Bin5
Succ Bin5 :: Bin
= 'BP ('B0 ('B1 'BE))
Succ   :: Bin -> Bin
Succ`  :: Bin -> BinP
Succ'` :: BinP -> Bin

type family Succ' (b :: Bin) :: BinP where ... Source #

Equations

Succ' 'BZ = 'BE 
Succ' ('BP b) = Succ b 

type Succ'' b = 'BP (Succ b) Source #

withSucc :: forall b r. SBinI b => Proxy b -> (SBinPI (Succ' b) => r) -> r Source #

Predecessor

type family Pred (b :: BinP) :: Bin where ... Source #

Predecessor type family..

>>> :kind! Pred BP.BinP1
Pred BP.BinP1 :: Bin
= 'BZ
>>> :kind! Pred BP.BinP5 == Bin4
Pred BP.BinP5 == Bin4 :: Bool
= 'True
>>> :kind! Pred BP.BinP8 == Bin7
Pred BP.BinP8 == Bin7 :: Bool
= 'True
>>> :kind! Pred BP.BinP6 == Bin5
Pred BP.BinP6 == Bin5 :: Bool
= 'True

Equations

Pred 'BE = 'BZ 
Pred ('B1 n) = 'BP ('B0 n) 
Pred ('B0 n) = 'BP (Pred' n) 

Addition

type family Plus (a :: Bin) (b :: Bin) :: Bin where ... Source #

Addition.

>>> :kind! Plus Bin3 Bin3 == Bin6
Plus Bin3 Bin3 == Bin6 :: Bool
= 'True
>>> :kind! Mult2 Bin3 == Bin6
Mult2 Bin3 == Bin6 :: Bool
= 'True

Equations

Plus 'BZ b = b 
Plus a 'BZ = a 
Plus ('BP a) ('BP b) = 'BP (Plus a b) 

Extras

type family Mult2 (b :: Bin) :: Bin where ... Source #

Multiply by two.

>>> :kind! Mult2 Bin0 == Bin0
Mult2 Bin0 == Bin0 :: Bool
= 'True
>>> :kind! Mult2 Bin3 == Bin6
Mult2 Bin3 == Bin6 :: Bool
= 'True

Equations

Mult2 'BZ = 'BZ 
Mult2 ('BP n) = 'BP ('B0 n) 

type family Mult2Plus1 (b :: Bin) :: BinP where ... Source #

Multiply by two and add one.

>>> :kind! Mult2Plus1 Bin0
Mult2Plus1 Bin0 :: BinP
= 'BE
>>> :kind! Mult2Plus1 Bin4 == BinP9
Mult2Plus1 Bin4 == BinP9 :: Bool
= 'True

Equations

Mult2Plus1 'BZ = 'BE 
Mult2Plus1 ('BP n) = 'B1 n 

Conversions

To GHC Nat

type family ToGHC (b :: Bin) :: Nat where ... Source #

Convert to GHC Nat.

>>> :kind! ToGHC Bin5
ToGHC Bin5 :: GHC.Nat...
= 5

Equations

ToGHC 'BZ = 0 
ToGHC ('BP n) = ToGHC n 

type family FromGHC (n :: Nat) :: Bin where ... Source #

Convert from GHC Nat.

>>> :kind! FromGHC 7
FromGHC 7 :: Bin
= 'BP ('B1 ('B1 'BE))

Equations

FromGHC n = FromGHC' (GhcDivMod2 n) 

To fin Nat

type family ToNat (b :: Bin) :: Nat where ... Source #

Convert to fin Nat.

>>> :kind! ToNat Bin5
ToNat Bin5 :: Nat
= 'S ('S ('S ('S ('S 'Z))))

Equations

ToNat 'BZ = 'Z 
ToNat ('BP n) = ToNat n 

type family FromNat (n :: Nat) :: Bin where ... Source #

Convert from fin Nat.

>>> :kind! FromNat N.Nat5
FromNat N.Nat5 :: Bin
= 'BP ('B1 ('B0 'BE))

Equations

FromNat n = FromNat' (DivMod2 n) 

Aliases

type Bin0 = 'BZ Source #

type Bin1 = 'BP BinP1 Source #

type Bin2 = 'BP BinP2 Source #

type Bin3 = 'BP BinP3 Source #

type Bin4 = 'BP BinP4 Source #

type Bin5 = 'BP BinP5 Source #

type Bin6 = 'BP BinP6 Source #

type Bin7 = 'BP BinP7 Source #

type Bin8 = 'BP BinP8 Source #

type Bin9 = 'BP BinP9 Source #