Safe Haskell | None |
---|---|
Language | Haskell2010 |
Parsers for fractions.
Synopsis
- 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, radixIn, isDigitIn, isNzDigitIn, fromDigitIn, fromNzDigitIn, unsafeFromDigitIn, intToDigitIn
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 #
Instances
The binary numeral system.
Instances
Eq Binary | |
Ord Binary | |
Read Binary | |
Show Binary | |
Generic Binary | |
PositionalSystem Binary | |
Defined in Text.Printer.Integral 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 # | |
BitSystem Binary | |
Defined in Text.Printer.Integral digitBitsIn :: Binary -> Int # digitMaskIn :: Num α => Binary -> α # lastDigitIn :: Bits α => Binary -> α -> Int # | |
type Rep Binary | |
The octal numeral system.
Instances
Eq Octal | |
Ord Octal | |
Read Octal | |
Show Octal | |
Generic Octal | |
PositionalSystem Octal | |
Defined in Text.Printer.Integral 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 # | |
BitSystem Octal | |
Defined in Text.Printer.Integral digitBitsIn :: Octal -> Int # digitMaskIn :: Num α => Octal -> α # lastDigitIn :: Bits α => Octal -> α -> Int # | |
type Rep Octal | |
The decimal numeral system.
Instances
Eq Decimal | |
Ord Decimal | |
Read Decimal | |
Show Decimal | |
Generic Decimal | |
PositionalSystem Decimal | |
Defined in Text.Printer.Integral systemName :: Decimal -> String # radixIn :: Num α => Decimal -> α # isDigitIn :: Decimal -> Char -> Bool # isNzDigitIn :: Decimal -> Char -> Bool # fromDigitIn :: Num α => Decimal -> Char -> Maybe α # fromNzDigitIn :: Num α => Decimal -> Char -> Maybe α # unsafeFromDigitIn :: Num α => Decimal -> Char -> α # intToDigitIn :: Decimal -> Int -> Char # printDigitIn :: Printer p => Decimal -> Char -> p # printZeroIn :: Printer p => Decimal -> p # | |
type Rep Decimal | |
data Hexadecimal #
The hexadecimal numeral system.
Instances
The hexadecimal numeral system, using upper case digits.
Instances
Eq UpHex | |
Ord UpHex | |
Read UpHex | |
Show UpHex | |
Generic UpHex | |
PositionalSystem UpHex | |
Defined in Text.Printer.Integral 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 # | |
BitSystem UpHex | |
Defined in Text.Printer.Integral digitBitsIn :: UpHex -> Int # digitMaskIn :: Num α => UpHex -> α # lastDigitIn :: Bits α => UpHex -> α -> Int # | |
type Rep UpHex | |
The hexadecimal numeral system, using lower case digits.
Instances
Eq LowHex | |
Ord LowHex | |
Read LowHex | |
Show LowHex | |
Generic LowHex | |
PositionalSystem LowHex | |
Defined in Text.Printer.Integral 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 # | |
BitSystem LowHex | |
Defined in Text.Printer.Integral digitBitsIn :: LowHex -> Int # digitMaskIn :: Num α => LowHex -> α # lastDigitIn :: Bits α => LowHex -> α -> Int # | |
type Rep LowHex | |
Sign
applySign :: Num α => Sign -> α -> α Source #
Negate the supplied value if the sign is NonPositive
and return it
as it is otherwise.
optMinus :: CharParsing μ => μ Sign Source #
Optional minus sign.
optSign :: CharParsing μ => μ Sign Source #
Optional minus or plus sign.
Optionality characteristic
Optionality characteristic.
Instances
Bounded Optional | |
Enum Optional | |
Eq Optional | |
Ord Optional | |
Defined in Text.Printer.Fractional | |
Read Optional | |
Show Optional | |
Ix Optional | |
Defined in Text.Printer.Fractional | |
Generic Optional | |
type Rep Optional | |
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
:: (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.