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

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
Arbitrary Bin Source # 
Instance details

Defined in Data.Bin

Methods

arbitrary :: Gen Bin #

shrink :: Bin -> [Bin] #

CoArbitrary Bin Source # 
Instance details

Defined in Data.Bin

Methods

coarbitrary :: Bin -> Gen b -> Gen b #

Function Bin Source # 
Instance details

Defined in Data.Bin

Methods

function :: (Bin -> b) -> Bin :-> b #

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 #

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

toConstr :: Bin -> Constr #

dataTypeOf :: Bin -> DataType #

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

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

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

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

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

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

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

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

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

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

Bits Bin Source # 
Instance details

Defined in Data.Bin

Methods

(.&.) :: Bin -> Bin -> Bin #

(.|.) :: Bin -> Bin -> Bin #

xor :: Bin -> Bin -> Bin #

complement :: Bin -> Bin #

shift :: Bin -> Int -> Bin #

rotate :: Bin -> Int -> Bin #

zeroBits :: Bin #

bit :: Int -> Bin #

setBit :: Bin -> Int -> Bin #

clearBit :: Bin -> Int -> Bin #

complementBit :: Bin -> Int -> Bin #

testBit :: Bin -> Int -> Bool #

bitSizeMaybe :: Bin -> Maybe Int #

bitSize :: Bin -> Int #

isSigned :: Bin -> Bool #

shiftL :: Bin -> Int -> Bin #

unsafeShiftL :: Bin -> Int -> Bin #

shiftR :: Bin -> Int -> Bin #

unsafeShiftR :: Bin -> Int -> Bin #

rotateL :: Bin -> Int -> Bin #

rotateR :: Bin -> Int -> Bin #

popCount :: Bin -> Int #

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

Methods

succ :: Bin -> Bin #

pred :: Bin -> Bin #

toEnum :: Int -> Bin #

fromEnum :: Bin -> Int #

enumFrom :: Bin -> [Bin] #

enumFromThen :: Bin -> Bin -> [Bin] #

enumFromTo :: Bin -> Bin -> [Bin] #

enumFromThenTo :: Bin -> Bin -> Bin -> [Bin] #

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

Methods

(+) :: Bin -> Bin -> Bin #

(-) :: Bin -> Bin -> Bin #

(*) :: Bin -> Bin -> Bin #

negate :: Bin -> Bin #

abs :: Bin -> Bin #

signum :: Bin -> Bin #

fromInteger :: Integer -> Bin #

Integral Bin Source # 
Instance details

Defined in Data.Bin

Methods

quot :: Bin -> Bin -> Bin #

rem :: Bin -> Bin -> Bin #

div :: Bin -> Bin -> Bin #

mod :: Bin -> Bin -> Bin #

quotRem :: Bin -> Bin -> (Bin, Bin) #

divMod :: Bin -> Bin -> (Bin, Bin) #

toInteger :: Bin -> Integer #

Real Bin Source # 
Instance details

Defined in Data.Bin

Methods

toRational :: Bin -> Rational #

Show Bin Source #

Bin is printed as Natural.

To see explicit structure, use explicitShow or explicitShowsPrec

Instance details

Defined in Data.Bin

Methods

showsPrec :: Int -> Bin -> ShowS #

show :: Bin -> String #

showList :: [Bin] -> ShowS #

NFData Bin Source # 
Instance details

Defined in Data.Bin

Methods

rnf :: Bin -> () #

Eq Bin Source # 
Instance details

Defined in Data.Bin

Methods

(==) :: Bin -> Bin -> Bool #

(/=) :: Bin -> Bin -> Bool #

Ord Bin Source # 
Instance details

Defined in Data.Bin

Methods

compare :: Bin -> Bin -> Ordering #

(<) :: Bin -> Bin -> Bool #

(<=) :: Bin -> Bin -> Bool #

(>) :: Bin -> Bin -> Bool #

(>=) :: Bin -> Bin -> Bool #

max :: Bin -> Bin -> Bin #

min :: Bin -> Bin -> Bin #

Hashable Bin Source # 
Instance details

Defined in Data.Bin

Methods

hashWithSalt :: Int -> Bin -> Int #

hash :: Bin -> Int #

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 Pos Source #
>>> eqp (top :: Pos Bin4) (top :: Pos Bin6)
True
>>> let xs = universe @Bin4; ys = universe @Bin6 in traverse_ print [ [ eqp x y | y <- ys ] | x <- xs ]
[True,False,False,False,False,False]
[False,True,False,False,False,False]
[False,False,True,False,False,False]
[False,False,False,True,False,False]

Since: 0.1.3

Instance details

Defined in Data.Bin.Pos

Methods

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

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 Pos Source #

Since: 0.1.3

Instance details

Defined in Data.Bin.Pos

Methods

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

GShow SBin Source #

Since: 0.1.2

Instance details

Defined in Data.Type.Bin

Methods

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

OrdP Pos Source #
>>> let xs = universe @Bin4; ys = universe @Bin6 in traverse_ print [ [ comparep x y | y <- ys ] | x <- xs ]
[EQ,LT,LT,LT,LT,LT]
[GT,EQ,LT,LT,LT,LT]
[GT,GT,EQ,LT,LT,LT]
[GT,GT,GT,EQ,LT,LT]

Since: 0.1.3

Instance details

Defined in Data.Bin.Pos

Methods

comparep :: forall (a :: k) (b :: k). Pos a -> Pos b -> Ordering #

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
Arbitrary BinP Source # 
Instance details

Defined in Data.BinP

Methods

arbitrary :: Gen BinP #

shrink :: BinP -> [BinP] #

CoArbitrary BinP Source # 
Instance details

Defined in Data.BinP

Methods

coarbitrary :: BinP -> Gen b -> Gen b #

Function BinP Source # 
Instance details

Defined in Data.BinP

Methods

function :: (BinP -> b) -> BinP :-> b #

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 #

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

toConstr :: BinP -> Constr #

dataTypeOf :: BinP -> DataType #

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

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

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

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

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

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

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

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

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

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

Bits BinP Source #

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

Instance details

Defined in Data.BinP

Enum BinP Source # 
Instance details

Defined in Data.BinP

Methods

succ :: BinP -> BinP #

pred :: BinP -> BinP #

toEnum :: Int -> BinP #

fromEnum :: BinP -> Int #

enumFrom :: BinP -> [BinP] #

enumFromThen :: BinP -> BinP -> [BinP] #

enumFromTo :: BinP -> BinP -> [BinP] #

enumFromThenTo :: BinP -> BinP -> BinP -> [BinP] #

Num BinP Source # 
Instance details

Defined in Data.BinP

Methods

(+) :: BinP -> BinP -> BinP #

(-) :: BinP -> BinP -> BinP #

(*) :: BinP -> BinP -> BinP #

negate :: BinP -> BinP #

abs :: BinP -> BinP #

signum :: BinP -> BinP #

fromInteger :: Integer -> BinP #

Integral BinP Source # 
Instance details

Defined in Data.BinP

Methods

quot :: BinP -> BinP -> BinP #

rem :: BinP -> BinP -> BinP #

div :: BinP -> BinP -> BinP #

mod :: BinP -> BinP -> BinP #

quotRem :: BinP -> BinP -> (BinP, BinP) #

divMod :: BinP -> BinP -> (BinP, BinP) #

toInteger :: BinP -> Integer #

Real BinP Source # 
Instance details

Defined in Data.BinP

Methods

toRational :: BinP -> Rational #

Show BinP Source # 
Instance details

Defined in Data.BinP

Methods

showsPrec :: Int -> BinP -> ShowS #

show :: BinP -> String #

showList :: [BinP] -> ShowS #

NFData BinP Source # 
Instance details

Defined in Data.BinP

Methods

rnf :: BinP -> () #

Eq BinP Source # 
Instance details

Defined in Data.BinP

Methods

(==) :: BinP -> BinP -> Bool #

(/=) :: BinP -> BinP -> Bool #

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

Defined in Data.BinP

Methods

compare :: BinP -> BinP -> Ordering #

(<) :: BinP -> BinP -> Bool #

(<=) :: BinP -> BinP -> Bool #

(>) :: BinP -> BinP -> Bool #

(>=) :: BinP -> BinP -> Bool #

max :: BinP -> BinP -> BinP #

min :: BinP -> BinP -> BinP #

Hashable BinP Source # 
Instance details

Defined in Data.BinP

Methods

hashWithSalt :: Int -> BinP -> Int #

hash :: BinP -> Int #

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 PosP Source #

Since: 0.1.3

Instance details

Defined in Data.BinP.PosP

Methods

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

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 PosP Source #

Since: 0.1.3

Instance details

Defined in Data.BinP.PosP

Methods

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

GShow SBinP Source #

Since: 0.1.2

Instance details

Defined in Data.Type.BinP

Methods

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

OrdP PosP Source #

Since: 0.1.3

Instance details

Defined in Data.BinP.PosP

Methods

comparep :: forall (a :: k) (b :: k). PosP a -> PosP b -> Ordering #

SNatI n => GShow (PosP' n :: BinP -> Type) Source #

Since: 0.1.3

Instance details

Defined in Data.BinP.PosP

Methods

gshowsPrec :: forall (a :: k). Int -> PosP' n a -> ShowS #

Showing

explicitShow :: Bin -> String Source #

show displaying a structure of Bin.

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

explicitShowsPrec :: Int -> Bin -> ShowS Source #

showsPrec displaying a structure of Bin.

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