Safe Haskell | Safe |
---|---|
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)
- type family EqBin (n :: Bin) (m :: Bin) where ...
- 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 | |
EqP SBin Source # | Since: 0.1.3 |
GNFData SBin Source # | Since: 0.1.2 |
Defined in Data.Type.Bin | |
GEq SBin Source # | Since: 0.1.2 |
GShow SBin Source # | Since: 0.1.2 |
Defined in Data.Type.Bin gshowsPrec :: forall (a :: k). Int -> SBin a -> ShowS # | |
Show (SBin b) Source # | |
SBinI b => Boring (SBin b) Source # | Since: 0.1.2 |
Defined in Data.Type.Bin | |
NFData (SBin n) Source # | Since: 0.1.2 |
Defined in Data.Type.Bin | |
Eq (SBin a) Source # | Since: 0.1.3 |
Ord (SBin a) Source # | Since: 0.1.3 |
data SBinP (b :: BinP) where Source #
Singleton of BinP
.
Instances
TestEquality SBinP Source # | |
Defined in Data.Type.BinP | |
EqP SBinP Source # | Since: 0.1.3 |
GNFData SBinP Source # | Since: 0.1.2 |
Defined in Data.Type.BinP | |
GEq SBinP Source # | Since: 0.1.2 |
GShow SBinP Source # | Since: 0.1.2 |
Defined in Data.Type.BinP gshowsPrec :: forall (a :: k). Int -> SBinP a -> ShowS # | |
Show (SBinP b) Source # | |
SBinPI b => Boring (SBinP b) Source # | Since: 0.1.2 |
Defined in Data.Type.BinP | |
NFData (SBinP n) Source # | Since: 0.1.2 |
Defined in Data.Type.BinP | |
Eq (SBinP a) Source # | Since: 0.1.3 |
Ord (SBinP a) Source # | Since: 0.1.3 |
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
:: 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
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
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
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
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
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))