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

Safe HaskellNone

Text.Printer.Integral

Contents

Description

Print integral numbers in common positional numeral systems.

Synopsis

Positional systems

class PositionalSystem s whereSource

Positional numeral system.

Methods

systemName :: s -> StringSource

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

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

The radix of the system.

isDigitIn :: s -> Char -> BoolSource

Test if a character is a digit.

isNzDigitIn :: s -> Char -> BoolSource

Test if a character is a non-zero digit.

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

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

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

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

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

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

intToDigitIn :: s -> Int -> CharSource

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

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

Print a digit.

printZeroIn :: Printer p => s -> pSource

class PositionalSystem s => BitSystem s whereSource

Positonal numeral system with a power of two radix.

Methods

digitBitsIn :: s -> IntSource

Numer of bits occupied by a digit.

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

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

lastDigitIn :: Bits α => s -> α -> IntSource

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

data Binary Source

The binary numeral system.

Constructors

Binary 

data Octal Source

The octal numeral system.

Constructors

Octal 

data Decimal Source

The decimal numeral system.

Constructors

Decimal 

data Hexadecimal Source

The hexadecimal numeral system.

Constructors

Hexadecimal 

data LowHex Source

The hexadecimal numeral system, using lower case digits.

Constructors

LowHex 

data UpHex Source

The hexadecimal numeral system, using upper case digits.

Constructors

UpHex 

Numeral printers

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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) => α -> pSource

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

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

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

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

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

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

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

number'Source

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 -> α -> pSource

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

binary'Source

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) => α -> pSource

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

octal'Source

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) => α -> pSource

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

decimal'Source

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) => α -> pSource

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

lowHex'Source

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) => α -> pSource

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

upHex'Source

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) => α -> pSource

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

bits'Source

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 -> α -> pSource

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

binaryBits'Source

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) => α -> pSource

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

octalBits'Source

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) => α -> pSource

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

lowHexBits'Source

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) => α -> pSource

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

upHexBits'Source

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) => α -> pSource

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