data-textual-0.3.0.1: Human-friendly textual representations.

Safe HaskellNone

Data.Textual.Fractional

Contents

Description

Parsers for fractions.

Synopsis

Positional numeral 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

data Binary

The binary numeral system.

Constructors

Binary 

data Octal

The octal numeral system.

Constructors

Octal 

data Decimal

The decimal numeral system.

Constructors

Decimal 

data Hexadecimal

The hexadecimal numeral system.

Constructors

Hexadecimal 

data UpHex

The hexadecimal numeral system, using upper case digits.

Constructors

UpHex 

data LowHex

The hexadecimal numeral system, using lower case digits.

Constructors

LowHex 

Sign

data Sign Source

Sign of a number.

Constructors

NonNegative 
NonPositive 

applySign :: Num α => Sign -> α -> αSource

Negate the supplied value if the sign is NonPositive and return it as it is otherwise.

optMinus :: CharParsing μ => μ SignSource

Optional minus sign.

optSign :: CharParsing μ => μ SignSource

Optional minus or plus sign.

Optionality characteristic

data Optional

Optionality characteristic.

Constructors

Optional 
Required 

isOptional :: Optional -> Bool

True if the supplied value is Optional and false otherwise.

isRequired :: Optional -> Bool

True if the supplied value is Required and false otherwise.

Fraction parsers

optSlash :: (Monad μ, CharParsing μ) => μ OptionalSource

Accept a slash and return Required. Otherwise return Optional.

fraction'Source

Arguments

:: (PositionalSystem s, Fractional α, Monad μ, CharParsing μ) 
=> μ Sign

Sign parser

-> s 
-> μ Optional

Numerator/denominator separator parser

-> μ α 

Parse a fraction. The numerator and the denominator are expected to be written in the specified positional numeral system.

fraction :: (Fractional α, Monad μ, CharParsing μ) => μ αSource

s-fraction parsers

decExpSign :: (Monad μ, CharParsing μ) => μ (Maybe Sign)Source

Start of a decimal exponent. Accepts 'e' or 'E' followed by an optional sign. Otherwise Nothing is returned.

hexExpSign :: (Monad μ, CharParsing μ) => μ (Maybe Sign)Source

Start of a hexadecimal exponent. Accepts 'p' or 'P' followed by an optional sign. Otherwise Nothing is returned.

fractional'Source

Arguments

:: (PositionalSystem s, Fractional α, Monad μ, CharParsing μ) 
=> μ Sign

Sign parser.

-> s 
-> Optional

Whether the integer part is optional.

-> μ ()

Dot parser.

-> μ (Maybe Sign)

Exponent start parser.

-> μ α 

s-fraction parser.

fractional :: (Monad μ, Fractional α, CharParsing μ) => μ αSource

Decimal fraction parser.