Safe Haskell | None |
---|---|
Language | Haskell2010 |
Binary natural numbers. DataKinds
stuff.
Synopsis
- data SBin (b :: Bin) where
- data SBinP (b :: BinP) where
- sbinToBin :: forall n. SBin n -> Bin
- sbinpToBinP :: forall n. SBinP n -> BinP
- sbinToNatural :: forall n. SBin n -> Natural
- sbinpToNatural :: forall n. SBinP n -> Natural
- class SBinI (b :: Bin) where
- class SBinPI (b :: BinP) where
- withSBin :: SBin b -> (SBinI b => r) -> r
- withSBinP :: SBinP b -> (SBinPI b => r) -> r
- reify :: forall r. Bin -> (forall b. SBinI b => Proxy b -> r) -> r
- reflect :: forall b proxy. SBinI b => proxy b -> Bin
- reflectToNum :: forall b proxy a. (SBinI b, Num a) => proxy b -> a
- eqBin :: forall a b. (SBinI a, SBinI b) => Maybe (a :~: b)
- induction :: forall b f. SBinI b => f BZ -> f (BP BE) -> (forall bb. SBinPI bb => f (BP bb) -> f (BP (B0 bb))) -> (forall bb. SBinPI bb => f (BP bb) -> f (BP (B1 bb))) -> f b
- type Succ b = BP (Succ' b)
- type family Succ' (b :: Bin) :: BinP where ...
- type Succ'' b = BP (Succ b)
- withSucc :: forall b r. SBinI b => Proxy b -> (SBinPI (Succ' b) => r) -> r
- type family Pred (b :: BinP) :: Bin where ...
- type family Plus (a :: Bin) (b :: Bin) :: Bin where ...
- type family Mult2 (b :: Bin) :: Bin where ...
- type family Mult2Plus1 (b :: Bin) :: BinP where ...
- type family ToGHC (b :: Bin) :: Nat where ...
- type family FromGHC (n :: Nat) :: Bin where ...
- type family ToNat (b :: Bin) :: Nat where ...
- type family FromNat (n :: Nat) :: Bin where ...
- type Bin0 = BZ
- type Bin1 = BP BinP1
- type Bin2 = BP BinP2
- type Bin3 = BP BinP3
- type Bin4 = BP BinP4
- type Bin5 = BP BinP5
- type Bin6 = BP BinP6
- type Bin7 = BP BinP7
- type Bin8 = BP BinP8
- type Bin9 = BP BinP9
Singleton
data SBin (b :: Bin) where Source #
Singleton of Bin
.
Instances
TestEquality SBin Source # | |
Defined in Data.Type.Bin |
data SBinP (b :: BinP) where Source #
Singleton of BinP
.
Instances
TestEquality SBinP Source # | |
Defined in Data.Type.BinP |
sbinToNatural :: forall n. SBin n -> Natural Source #
sbinpToNatural :: forall n. SBinP n -> Natural Source #
Implicit
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 #
Type equality
Induction
:: 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
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
Pred BP.BinP5 :: Bin = 'BP ('B0 ('B0 BP.BinP1))
>>>
:kind! Pred BP.BinP8
Pred BP.BinP8 :: Bin = 'BP ('B1 ('B1 'BE))
>>>
:kind! Pred BP.BinP6
Pred BP.BinP6 :: Bin = 'BP ('B1 ('B0 'BE))
Addition
type family Plus (a :: Bin) (b :: Bin) :: Bin where ... Source #
Addition.
>>>
:kind! Plus Bin7 Bin7
Plus Bin7 Bin7 :: Bin = 'BP ('B0 ('B1 ('B1 'BE)))
>>>
:kind! Mult2 Bin7
Mult2 Bin7 :: Bin = 'BP ('B0 ('B1 BinP3))
Extras
type family Mult2 (b :: Bin) :: Bin where ... Source #
Multiply by two.
>>>
:kind! Mult2 Bin0
Mult2 Bin0 :: Bin = 'BZ
>>>
:kind! Mult2 Bin7
Mult2 Bin7 :: Bin = 'BP ('B0 ('B1 BinP3))
type family Mult2Plus1 (b :: Bin) :: BinP where ... Source #
Multiply by two and add one.
>>>
:kind! Mult2Plus1 Bin0
Mult2Plus1 Bin0 :: BinP = 'BE
>>>
:kind! Mult2Plus1 Bin5
Mult2Plus1 Bin5 :: BinP = 'B1 ('B1 BinP2)
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
type family FromGHC (n :: Nat) :: Bin where ... Source #
Convert from GHC Nat
.
>>>
:kind! FromGHC 7
FromGHC 7 :: Bin = 'BP ('B1 ('B1 'BE))
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))))
type family FromNat (n :: Nat) :: Bin where ... Source #
Convert from fin
Nat
.
>>>
:kind! FromNat N.Nat5
FromNat N.Nat5 :: Bin = 'BP ('B1 ('B0 'BE))