text-printer-0.5: Abstract interface for text builders/printers.

Safe HaskellNone
LanguageHaskell2010

Text.Printer.Integral

Contents

Description

Print integral numbers in common positional numeral systems.

Synopsis

Positional systems

class PositionalSystem s where #

Positional numeral system.

Methods

systemName :: s -> String #

The name of the system (e.g. "binary", "decimal").

radixIn :: Num α => s -> α #

The radix of the system.

isDigitIn :: s -> Char -> Bool #

Test if a character is a digit.

isNzDigitIn :: s -> Char -> Bool #

Test if a character is a non-zero digit.

fromDigitIn :: Num α => s -> Char -> Maybe α #

Map digits to the corresponding numbers. Return Nothing on other inputs.

fromNzDigitIn :: Num α => s -> Char -> Maybe α #

Map non-zero digits to the corresponding numbers. Return Nothing on other inputs.

unsafeFromDigitIn :: Num α => s -> Char -> α #

Map digits to the corresponding numbers. No checks are performed.

intToDigitIn :: s -> Int -> Char #

Map Int values to the corresponding digits. Inputs must be non-negative and less than the radix.

printDigitIn :: Printer p => s -> Char -> p #

Print a digit.

printZeroIn :: Printer p => s -> p #

Instances

PositionalSystem UpHex # 

Methods

systemName :: UpHex -> String #

radixIn :: Num α => UpHex -> α #

isDigitIn :: UpHex -> Char -> Bool #

isNzDigitIn :: UpHex -> Char -> Bool #

fromDigitIn :: Num α => UpHex -> Char -> Maybe α #

fromNzDigitIn :: Num α => UpHex -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => UpHex -> Char -> α #

intToDigitIn :: UpHex -> Int -> Char #

printDigitIn :: Printer p => UpHex -> Char -> p #

printZeroIn :: Printer p => UpHex -> p #

PositionalSystem LowHex # 

Methods

systemName :: LowHex -> String #

radixIn :: Num α => LowHex -> α #

isDigitIn :: LowHex -> Char -> Bool #

isNzDigitIn :: LowHex -> Char -> Bool #

fromDigitIn :: Num α => LowHex -> Char -> Maybe α #

fromNzDigitIn :: Num α => LowHex -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => LowHex -> Char -> α #

intToDigitIn :: LowHex -> Int -> Char #

printDigitIn :: Printer p => LowHex -> Char -> p #

printZeroIn :: Printer p => LowHex -> p #

PositionalSystem Hexadecimal # 
PositionalSystem Decimal # 
PositionalSystem Octal # 

Methods

systemName :: Octal -> String #

radixIn :: Num α => Octal -> α #

isDigitIn :: Octal -> Char -> Bool #

isNzDigitIn :: Octal -> Char -> Bool #

fromDigitIn :: Num α => Octal -> Char -> Maybe α #

fromNzDigitIn :: Num α => Octal -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => Octal -> Char -> α #

intToDigitIn :: Octal -> Int -> Char #

printDigitIn :: Printer p => Octal -> Char -> p #

printZeroIn :: Printer p => Octal -> p #

PositionalSystem Binary # 

Methods

systemName :: Binary -> String #

radixIn :: Num α => Binary -> α #

isDigitIn :: Binary -> Char -> Bool #

isNzDigitIn :: Binary -> Char -> Bool #

fromDigitIn :: Num α => Binary -> Char -> Maybe α #

fromNzDigitIn :: Num α => Binary -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => Binary -> Char -> α #

intToDigitIn :: Binary -> Int -> Char #

printDigitIn :: Printer p => Binary -> Char -> p #

printZeroIn :: Printer p => Binary -> p #

class PositionalSystem s => BitSystem s where #

Positonal numeral system with a power of two radix.

Minimal complete definition

digitBitsIn, digitMaskIn, lastDigitIn

Methods

digitBitsIn :: s -> Int #

Numer of bits occupied by a digit.

digitMaskIn :: Num α => s -> α #

The number that has digitBitsIn least significant bits set to ones and all the other bits set to zeroes.

lastDigitIn :: Bits α => s -> α -> Int #

Map the last digit of a number to the corresponding Int value.

Instances

BitSystem UpHex # 

Methods

digitBitsIn :: UpHex -> Int #

digitMaskIn :: Num α => UpHex -> α #

lastDigitIn :: Bits α => UpHex -> α -> Int #

BitSystem LowHex # 

Methods

digitBitsIn :: LowHex -> Int #

digitMaskIn :: Num α => LowHex -> α #

lastDigitIn :: Bits α => LowHex -> α -> Int #

BitSystem Hexadecimal # 

Methods

digitBitsIn :: Hexadecimal -> Int #

digitMaskIn :: Num α => Hexadecimal -> α #

lastDigitIn :: Bits α => Hexadecimal -> α -> Int #

BitSystem Octal # 

Methods

digitBitsIn :: Octal -> Int #

digitMaskIn :: Num α => Octal -> α #

lastDigitIn :: Bits α => Octal -> α -> Int #

BitSystem Binary # 

Methods

digitBitsIn :: Binary -> Int #

digitMaskIn :: Num α => Binary -> α #

lastDigitIn :: Bits α => Binary -> α -> Int #

data Binary #

The binary numeral system.

Constructors

Binary 

Instances

Eq Binary # 

Methods

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

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

Ord Binary # 
Read Binary # 
Show Binary # 
Generic Binary # 

Associated Types

type Rep Binary :: * -> * #

Methods

from :: Binary -> Rep Binary x #

to :: Rep Binary x -> Binary #

BitSystem Binary # 

Methods

digitBitsIn :: Binary -> Int #

digitMaskIn :: Num α => Binary -> α #

lastDigitIn :: Bits α => Binary -> α -> Int #

PositionalSystem Binary # 

Methods

systemName :: Binary -> String #

radixIn :: Num α => Binary -> α #

isDigitIn :: Binary -> Char -> Bool #

isNzDigitIn :: Binary -> Char -> Bool #

fromDigitIn :: Num α => Binary -> Char -> Maybe α #

fromNzDigitIn :: Num α => Binary -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => Binary -> Char -> α #

intToDigitIn :: Binary -> Int -> Char #

printDigitIn :: Printer p => Binary -> Char -> p #

printZeroIn :: Printer p => Binary -> p #

type Rep Binary # 
type Rep Binary = D1 (MetaData "Binary" "Text.Printer.Integral" "text-printer-0.5-2ZMxDVmuOLd2v5RWoP177I" False) (C1 (MetaCons "Binary" PrefixI False) U1)

data Octal #

The octal numeral system.

Constructors

Octal 

Instances

Eq Octal # 

Methods

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

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

Ord Octal # 

Methods

compare :: Octal -> Octal -> Ordering #

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

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

(>) :: Octal -> Octal -> Bool #

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

max :: Octal -> Octal -> Octal #

min :: Octal -> Octal -> Octal #

Read Octal # 
Show Octal # 

Methods

showsPrec :: Int -> Octal -> ShowS #

show :: Octal -> String #

showList :: [Octal] -> ShowS #

Generic Octal # 

Associated Types

type Rep Octal :: * -> * #

Methods

from :: Octal -> Rep Octal x #

to :: Rep Octal x -> Octal #

BitSystem Octal # 

Methods

digitBitsIn :: Octal -> Int #

digitMaskIn :: Num α => Octal -> α #

lastDigitIn :: Bits α => Octal -> α -> Int #

PositionalSystem Octal # 

Methods

systemName :: Octal -> String #

radixIn :: Num α => Octal -> α #

isDigitIn :: Octal -> Char -> Bool #

isNzDigitIn :: Octal -> Char -> Bool #

fromDigitIn :: Num α => Octal -> Char -> Maybe α #

fromNzDigitIn :: Num α => Octal -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => Octal -> Char -> α #

intToDigitIn :: Octal -> Int -> Char #

printDigitIn :: Printer p => Octal -> Char -> p #

printZeroIn :: Printer p => Octal -> p #

type Rep Octal # 
type Rep Octal = D1 (MetaData "Octal" "Text.Printer.Integral" "text-printer-0.5-2ZMxDVmuOLd2v5RWoP177I" False) (C1 (MetaCons "Octal" PrefixI False) U1)

data Decimal #

The decimal numeral system.

Constructors

Decimal 

Instances

Eq Decimal # 

Methods

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

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

Ord Decimal # 
Read Decimal # 
Show Decimal # 
Generic Decimal # 

Associated Types

type Rep Decimal :: * -> * #

Methods

from :: Decimal -> Rep Decimal x #

to :: Rep Decimal x -> Decimal #

PositionalSystem Decimal # 
type Rep Decimal # 
type Rep Decimal = D1 (MetaData "Decimal" "Text.Printer.Integral" "text-printer-0.5-2ZMxDVmuOLd2v5RWoP177I" False) (C1 (MetaCons "Decimal" PrefixI False) U1)

data Hexadecimal #

The hexadecimal numeral system.

Constructors

Hexadecimal 

Instances

Eq Hexadecimal # 
Ord Hexadecimal # 
Read Hexadecimal # 
Show Hexadecimal # 
Generic Hexadecimal # 

Associated Types

type Rep Hexadecimal :: * -> * #

BitSystem Hexadecimal # 

Methods

digitBitsIn :: Hexadecimal -> Int #

digitMaskIn :: Num α => Hexadecimal -> α #

lastDigitIn :: Bits α => Hexadecimal -> α -> Int #

PositionalSystem Hexadecimal # 
type Rep Hexadecimal # 
type Rep Hexadecimal = D1 (MetaData "Hexadecimal" "Text.Printer.Integral" "text-printer-0.5-2ZMxDVmuOLd2v5RWoP177I" False) (C1 (MetaCons "Hexadecimal" PrefixI False) U1)

data LowHex #

The hexadecimal numeral system, using lower case digits.

Constructors

LowHex 

Instances

Eq LowHex # 

Methods

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

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

Ord LowHex # 
Read LowHex # 
Show LowHex # 
Generic LowHex # 

Associated Types

type Rep LowHex :: * -> * #

Methods

from :: LowHex -> Rep LowHex x #

to :: Rep LowHex x -> LowHex #

BitSystem LowHex # 

Methods

digitBitsIn :: LowHex -> Int #

digitMaskIn :: Num α => LowHex -> α #

lastDigitIn :: Bits α => LowHex -> α -> Int #

PositionalSystem LowHex # 

Methods

systemName :: LowHex -> String #

radixIn :: Num α => LowHex -> α #

isDigitIn :: LowHex -> Char -> Bool #

isNzDigitIn :: LowHex -> Char -> Bool #

fromDigitIn :: Num α => LowHex -> Char -> Maybe α #

fromNzDigitIn :: Num α => LowHex -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => LowHex -> Char -> α #

intToDigitIn :: LowHex -> Int -> Char #

printDigitIn :: Printer p => LowHex -> Char -> p #

printZeroIn :: Printer p => LowHex -> p #

type Rep LowHex # 
type Rep LowHex = D1 (MetaData "LowHex" "Text.Printer.Integral" "text-printer-0.5-2ZMxDVmuOLd2v5RWoP177I" False) (C1 (MetaCons "LowHex" PrefixI False) U1)

data UpHex #

The hexadecimal numeral system, using upper case digits.

Constructors

UpHex 

Instances

Eq UpHex # 

Methods

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

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

Ord UpHex # 

Methods

compare :: UpHex -> UpHex -> Ordering #

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

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

(>) :: UpHex -> UpHex -> Bool #

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

max :: UpHex -> UpHex -> UpHex #

min :: UpHex -> UpHex -> UpHex #

Read UpHex # 
Show UpHex # 

Methods

showsPrec :: Int -> UpHex -> ShowS #

show :: UpHex -> String #

showList :: [UpHex] -> ShowS #

Generic UpHex # 

Associated Types

type Rep UpHex :: * -> * #

Methods

from :: UpHex -> Rep UpHex x #

to :: Rep UpHex x -> UpHex #

BitSystem UpHex # 

Methods

digitBitsIn :: UpHex -> Int #

digitMaskIn :: Num α => UpHex -> α #

lastDigitIn :: Bits α => UpHex -> α -> Int #

PositionalSystem UpHex # 

Methods

systemName :: UpHex -> String #

radixIn :: Num α => UpHex -> α #

isDigitIn :: UpHex -> Char -> Bool #

isNzDigitIn :: UpHex -> Char -> Bool #

fromDigitIn :: Num α => UpHex -> Char -> Maybe α #

fromNzDigitIn :: Num α => UpHex -> Char -> Maybe α #

unsafeFromDigitIn :: Num α => UpHex -> Char -> α #

intToDigitIn :: UpHex -> Int -> Char #

printDigitIn :: Printer p => UpHex -> Char -> p #

printZeroIn :: Printer p => UpHex -> p #

type Rep UpHex # 
type Rep UpHex = D1 (MetaData "UpHex" "Text.Printer.Integral" "text-printer-0.5-2ZMxDVmuOLd2v5RWoP177I" False) (C1 (MetaCons "UpHex" PrefixI False) U1)

Numeral printers

nonNegative :: (PositionalSystem s, Integral α, Printer p) => s -> α -> p #

Print a non-negative number in the specified positional numeral system.

nnBinary :: (Integral α, Printer p) => α -> p #

Print a non-negative number in the binary numeral system.

nnOctal :: (Integral α, Printer p) => α -> p #

Print a non-negative number in the octal numeral system.

nnDecimal :: (Integral α, Printer p) => α -> p #

Print a non-negative number in the decimal numeral system.

nnLowHex :: (Integral α, Printer p) => α -> p #

Print a non-negative number in the hexadecimal numeral system using lower case digits.

nnUpHex :: (Integral α, Printer p) => α -> p #

Print a non-negative number in the hexadecimal numeral system using upper case digits.

nnBits :: (BitSystem s, Num α, Bits α, Printer p) => s -> α -> p #

Print a non-negative binary number in the specified positional numeral system.

nnBinaryBits :: (Num α, Bits α, Printer p) => α -> p #

Print a non-negative binary number in the binary numeral system.

nnOctalBits :: (Num α, Bits α, Printer p) => α -> p #

Print a non-negative binary number in the octal numeral system.

nnLowHexBits :: (Num α, Bits α, Printer p) => α -> p #

Print a non-negative binary number in the hexadecimal numeral system using lower case digits.

nnUpHexBits :: (Num α, Bits α, Printer p) => α -> p #

Print a non-negative binary number in the hexadecimal numeral system using upper case digits.

nonPositive :: (PositionalSystem s, Integral α, Printer p) => s -> α -> p #

Print a non-positive number in the specified positional numeral system. For example, nonPositive Decimal (-123) would print "123".

npBinary :: (Integral α, Printer p) => α -> p #

Print a non-positive number in the binary numeral system.

npOctal :: (Integral α, Printer p) => α -> p #

Print a non-positive number in the octal numeral system.

npDecimal :: (Integral α, Printer p) => α -> p #

Print a non-positive number in the decimal numeral system.

npLowHex :: (Integral α, Printer p) => α -> p #

Print a non-positive number in the hexadecimal numeral system using lower case digits.

npUpHex :: (Integral α, Printer p) => α -> p #

Print a non-positive number in the hexadecimal numeral system using upper case digits.

npBits :: (BitSystem s, Ord α, Num α, Bits α, Printer p) => s -> α -> p #

Print a non-positive two-compliment binary number in the specified positional numeral system. For example, npBits UpHex (-0xABC) would print "ABC".

npBinaryBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a non-positive binary number in the binary numeral system.

npOctalBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a non-positive binary number in the octal numeral system.

npLowHexBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a non-positive binary number in the hexadecimal numeral system using lower case digits.

npUpHexBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a non-positive binary number in the hexadecimal numeral system using upper case digits.

number' #

Arguments

:: (PositionalSystem s, Ord α, Integral α, Printer p) 
=> s 
-> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a number in the specified positional numeral system.

number :: (PositionalSystem s, Ord α, Integral α, Printer p) => s -> α -> p #

Print a number in the specified positional numeral system. Negative values are prefixed with a minus sign.

binary' #

Arguments

:: (Ord α, Integral α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a number in the binary numeral system.

binary :: (Ord α, Integral α, Printer p) => α -> p #

Print a number in the binary numeral system. Negative values are prefixed with a minus sign.

octal' #

Arguments

:: (Ord α, Integral α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a number in the octal numeral system.

octal :: (Ord α, Integral α, Printer p) => α -> p #

Print a number in the octal numeral system. Negative values are prefixed with a minus sign.

decimal' #

Arguments

:: (Ord α, Integral α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a number in the decimal numeral system.

decimal :: (Ord α, Integral α, Printer p) => α -> p #

Print a number in the decimal numeral system. Negative values are prefixed with a minus sign.

lowHex' #

Arguments

:: (Ord α, Integral α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a number in the hexadecimal numeral system using lower case digits.

lowHex :: (Ord α, Integral α, Printer p) => α -> p #

Print a number in the hexadecimal numeral system using lower case digits. Negative values are prefixed with a minus sign.

upHex' #

Arguments

:: (Ord α, Integral α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a number in the hexadecimal numeral system using upper case digits.

upHex :: (Ord α, Integral α, Printer p) => α -> p #

Print a number in the hexadecimal numeral system using upper case digits. Negative values are prefixed with a minus sign.

bits' #

Arguments

:: (BitSystem s, Ord α, Num α, Bits α, Printer p) 
=> s 
-> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a binary number in the specified positional numeral system.

bits :: (BitSystem s, Ord α, Num α, Bits α, Printer p) => s -> α -> p #

Print a binary number in the specified positional numeral system. Negative values are prefixed with a minus sign.

binaryBits' #

Arguments

:: (Ord α, Num α, Bits α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a binary number in the binary numeral system.

binaryBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a binary number in the binary numeral system. Negative values are prefixed with a minus sign.

octalBits' #

Arguments

:: (Ord α, Num α, Bits α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a binary number in the octal numeral system.

octalBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a binary number in the octal numeral system. Negative values are prefixed with a minus sign.

lowHexBits' #

Arguments

:: (Ord α, Num α, Bits α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a binary number in the hexadecimal numeral system using lower case digits.

lowHexBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a binary number in the hexadecimal numeral system using lower case digits. Negative values are prefixed with a minus sign.

upHexBits' #

Arguments

:: (Ord α, Num α, Bits α, Printer p) 
=> p

Prefix for negative values

-> p

Zero printer

-> p

Prefix for positive values

-> α 
-> p 

Print a binary number in the hexadecimal numeral system using upper case digits.

upHexBits :: (Ord α, Num α, Bits α, Printer p) => α -> p #

Print a binary number in the hexadecimal numeral system using upper case digits. Negative values are prefixed with a minus sign.