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

Data.Bin

Description

Binary natural numbers, Bin .

This module is designed to be imported qualified.

Synopsis

Binary natural numbers

data Bin Source #

Binary natural numbers.

Numbers are represented in little-endian order, the representation is unique.

>>> mapM_ (putStrLn .  explicitShow) [0 .. 7]
BZ
BP BE
BP (B0 BE)
BP (B1 BE)
BP (B0 (B0 BE))
BP (B1 (B0 BE))
BP (B0 (B1 BE))
BP (B1 (B1 BE))

Constructors

BZ

zero

BP BinP

non-zero

Instances

Instances details
Enum Bin Source #
>>> take 10 $ iterate succ BZ
[0,1,2,3,4,5,6,7,8,9]
>>> take 10 [BZ ..]
[0,1,2,3,4,5,6,7,8,9]
Instance details

Defined in Data.Bin

Eq Bin Source #
Instance details

Defined in Data.Bin

Integral Bin Source #
Instance details

Defined in Data.Bin

Data Bin Source #
Instance details

Defined in Data.Bin

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Bin -> c Bin Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c Bin Source #

toConstr :: Bin -> Constr Source #

dataTypeOf :: Bin -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c Bin ) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c Bin ) Source #

gmapT :: ( forall b. Data b => b -> b) -> Bin -> Bin Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Bin -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Bin -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Bin -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Bin -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Bin -> m Bin Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Bin -> m Bin Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Bin -> m Bin Source #

Num Bin Source #
>>> 0 + 2 :: Bin
2
>>> 1 + 2 :: Bin
3
>>> 4 * 8 :: Bin
32
>>> 7 * 7 :: Bin
49
Instance details

Defined in Data.Bin

Ord Bin Source #
Instance details

Defined in Data.Bin

Real Bin Source #
Instance details

Defined in Data.Bin

Show Bin Source #

Bin is printed as Natural .

To see explicit structure, use explicitShow or explicitShowsPrec

Instance details

Defined in Data.Bin

Function Bin Source #
Instance details

Defined in Data.Bin

Arbitrary Bin Source #
Instance details

Defined in Data.Bin

CoArbitrary Bin Source #
Instance details

Defined in Data.Bin

Bits Bin Source #
Instance details

Defined in Data.Bin

NFData Bin Source #
Instance details

Defined in Data.Bin

Methods

rnf :: Bin -> () Source #

Hashable Bin Source #
Instance details

Defined in Data.Bin

TestEquality SBin Source #
Instance details

Defined in Data.Type.Bin

Methods

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

toNatural :: Bin -> Natural Source #

Convert Bin to Natural

>>> toNatural 0
0
>>> toNatural 2
2
>>> toNatural $ BP $ B0 $ B1 $ BE
6

fromNatural :: Natural -> Bin Source #

Convert Natural to Nat

>>> fromNatural 4
4
>>> explicitShow (fromNatural 4)
"BP (B0 (B0 BE))"

toNat :: Bin -> Nat Source #

Convert from Bin to Nat .

>>> toNat 5
5
>>> N.explicitShow (toNat 5)
"S (S (S (S (S Z))))"

fromNat :: Nat -> Bin Source #

Convert from Nat to Bin .

>>> fromNat 5
5
>>> explicitShow (fromNat 5)
"BP (B1 (B0 BE))"

cata Source #

Arguments

:: a

\(0\)

-> a

\(1\)

-> (a -> a)

\(2x\)

-> (a -> a)

\(2x + 1\)

-> Bin
-> a

Fold Bin .

Positive natural numbers

data BinP Source #

Non-zero binary natural numbers.

We could have called this type Bin1 , but that's used as type alias for promoted BP BE in Data.Type.Bin .

Constructors

BE

one

B0 BinP

mult2

B1 BinP

mult2 plus 1

Instances

Instances details
Enum BinP Source #
Instance details

Defined in Data.BinP

Eq BinP Source #
Instance details

Defined in Data.BinP

Integral BinP Source #
Instance details

Defined in Data.BinP

Data BinP Source #
Instance details

Defined in Data.BinP

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> BinP -> c BinP Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c BinP Source #

toConstr :: BinP -> Constr Source #

dataTypeOf :: BinP -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c BinP ) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c BinP ) Source #

gmapT :: ( forall b. Data b => b -> b) -> BinP -> BinP Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> BinP -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> BinP -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> BinP -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> BinP -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> BinP -> m BinP Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> BinP -> m BinP Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> BinP -> m BinP Source #

Num BinP Source #
Instance details

Defined in Data.BinP

Ord BinP Source #
>>> sort [1 .. 9 :: BinP]
[1,2,3,4,5,6,7,8,9]
Instance details

Defined in Data.BinP

Real BinP Source #
Instance details

Defined in Data.BinP

Show BinP Source #
Instance details

Defined in Data.BinP

Function BinP Source #
Instance details

Defined in Data.BinP

Arbitrary BinP Source #
Instance details

Defined in Data.BinP

CoArbitrary BinP Source #
Instance details

Defined in Data.BinP

Bits BinP Source #

NOTE : .&. , xor , shiftR and rotateR are __NOT_ implemented. They may make number zero.

Instance details

Defined in Data.BinP

NFData BinP Source #
Instance details

Defined in Data.BinP

Hashable BinP Source #
Instance details

Defined in Data.BinP

TestEquality SBinP Source #
Instance details

Defined in Data.Type.BinP

Methods

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

Showing

explicitShow :: Bin -> String Source #

show displaying a structure of Bin .

>>> explicitShow 0
"BZ"
>>> explicitShow 2
"BP (B0 BE)"

Extras

predP :: BinP -> Bin Source #

This is a total function.

>>> map predP [1..10]
[0,1,2,3,4,5,6,7,8,9]

Data.Bits

Aliases