bin-0.1: Bin: binary natural numbers.
Safe Haskell None
Language Haskell2010

Data.Bin.Pos

Synopsis

Documentation

data Pos (b :: Bin ) where Source #

Pos is to Bin is what Fin is to Nat .

The name is picked, as sthe lack of beter alternatives.

Constructors

Pos :: PosP b -> Pos (' BP b)

Top & Pop

top :: SBinPI b => Pos (' BP b) Source #

top and pop serve as FZ and FS , with types specified so type-inference works backwards from the result.

>>> top :: Pos Bin4
0
>>> pop (pop top) :: Pos Bin4
2
>>> pop (pop top) :: Pos Bin9
2

Showing

Conversions

toNatural :: Pos b -> Natural Source #

Convert Pos to Natural

>>> map toNatural (universe :: [Pos Bin7])
[0,1,2,3,4,5,6]

Interesting

boring :: Pos (' BP ' BE ) Source #

Counting to one is boring

>>> boring
0

Weakening (succ)

weakenRight1 :: SBinPI b => Pos (' BP b) -> Pos ( Succ'' b) Source #

Like FS for Fin .

Some tests:

>>> map weakenRight1 $ (universe :: [Pos Bin2])
[1,2]
>>> map weakenRight1 $ (universe :: [Pos Bin3])
[1,2,3]
>>> map weakenRight1 $ (universe :: [Pos Bin4])
[1,2,3,4]
>>> map weakenRight1 $ (universe :: [Pos Bin5])
[1,2,3,4,5]
>>> map weakenRight1 $ (universe :: [Pos Bin6])
[1,2,3,4,5,6]

Universe

universe :: forall b. SBinI b => [ Pos b] Source #

Universe, i.e. all [Pos b]

>>> universe :: [Pos Bin9]
[0,1,2,3,4,5,6,7,8]
>>> traverse_ (putStrLn . explicitShow) (universe :: [Pos Bin5])
Pos (PosP (Here WE))
Pos (PosP (There1 (There0 (AtEnd 0b00))))
Pos (PosP (There1 (There0 (AtEnd 0b01))))
Pos (PosP (There1 (There0 (AtEnd 0b10))))
Pos (PosP (There1 (There0 (AtEnd 0b11))))