Safe Haskell | None |
---|
Parsers for fractions.
- class PositionalSystem s where
- systemName :: s -> String
- radixIn :: Num α => s -> α
- isDigitIn :: s -> Char -> Bool
- isNzDigitIn :: s -> Char -> Bool
- fromDigitIn :: Num α => s -> Char -> Maybe α
- fromNzDigitIn :: Num α => s -> Char -> Maybe α
- unsafeFromDigitIn :: Num α => s -> Char -> α
- intToDigitIn :: s -> Int -> Char
- printDigitIn :: Printer p => s -> Char -> p
- printZeroIn :: Printer p => s -> p
- data Binary = Binary
- data Octal = Octal
- data Decimal = Decimal
- data Hexadecimal = Hexadecimal
- data UpHex = UpHex
- data LowHex = LowHex
- data Sign
- applySign :: Num α => Sign -> α -> α
- optMinus :: CharParsing μ => μ Sign
- optSign :: CharParsing μ => μ Sign
- data Optional
- isOptional :: Optional -> Bool
- isRequired :: Optional -> Bool
- optSlash :: (Monad μ, CharParsing μ) => μ Optional
- fraction' :: (PositionalSystem s, Fractional α, Monad μ, CharParsing μ) => μ Sign -> s -> μ Optional -> μ α
- fraction :: (Fractional α, Monad μ, CharParsing μ) => μ α
- decExpSign :: (Monad μ, CharParsing μ) => μ (Maybe Sign)
- hexExpSign :: (Monad μ, CharParsing μ) => μ (Maybe Sign)
- fractional' :: (PositionalSystem s, Fractional α, Monad μ, CharParsing μ) => μ Sign -> s -> Optional -> μ () -> μ (Maybe Sign) -> μ α
- fractional :: (Monad μ, Fractional α, CharParsing μ) => μ α
Positional numeral systems
class PositionalSystem s where
Positional numeral system.
systemName :: s -> String
The name of the system (e.g. "binary", "decimal").
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.
data Octal
The octal numeral system.
data Decimal
The decimal numeral system.
data Hexadecimal
The hexadecimal numeral system.
data UpHex
The hexadecimal numeral system, using upper case digits.
data LowHex
The hexadecimal numeral system, using lower case digits.
Sign
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.
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
:: (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.
:: (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.