Data.Textual.Fractional

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

Safe Haskell | None
Language | Haskell2010

Data.Textual.Fractional

Contents

- Positional numeral systems
- Sign
- Optionality characteristic
- Fraction parsers
- s-fraction parsers

Description

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
  - = NonNegative
  - | NonPositive
- applySign :: Num α => Sign -> α -> α
- optMinus :: CharParsing μ => μ Sign
- optSign :: CharParsing μ => μ Sign
- data Optional :: *
  - = Optional
  - | Required
- 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.

Minimal complete definition

systemName, radixIn, isDigitIn, isNzDigitIn, fromDigitIn, fromNzDigitIn, unsafeFromDigitIn, intToDigitIn

Instances

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 #
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 Decimal |
Methods 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 #
PositionalSystem Hexadecimal |
Methods systemName :: Hexadecimal -> String # radixIn :: Num α => Hexadecimal -> α # isDigitIn :: Hexadecimal -> Char -> Bool # isNzDigitIn :: Hexadecimal -> Char -> Bool # fromDigitIn :: Num α => Hexadecimal -> Char -> Maybe α # fromNzDigitIn :: Num α => Hexadecimal -> Char -> Maybe α # unsafeFromDigitIn :: Num α => Hexadecimal -> Char -> α # intToDigitIn :: Hexadecimal -> Int -> Char # printDigitIn :: Printer p => Hexadecimal -> Char -> p # printZeroIn :: Printer p => Hexadecimal -> 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 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 #

data Binary :: * #

The binary numeral system.

Constructors

Binary |

Instances

Eq Binary |
Methods (==) :: Binary -> Binary -> Bool # (/=) :: Binary -> Binary -> Bool #
Ord Binary |
Methods compare :: Binary -> Binary -> Ordering # (<) :: Binary -> Binary -> Bool # (<=) :: Binary -> Binary -> Bool # (>) :: Binary -> Binary -> Bool # (>=) :: Binary -> Binary -> Bool # max :: Binary -> Binary -> Binary # min :: Binary -> Binary -> Binary #
Read Binary |
Methods readsPrec :: Int -> ReadS Binary # readList :: ReadS [Binary] # readPrec :: ReadPrec Binary # readListPrec :: ReadPrec [Binary] #
Show Binary |
Methods showsPrec :: Int -> Binary -> ShowS # show :: Binary -> String # showList :: [Binary] -> ShowS #
Generic Binary |
Associated Types type Rep Binary :: * -> * # Methods from :: Binary -> Rep Binary x # to :: Rep Binary x -> Binary #
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 #
BitSystem Binary |
Methods digitBitsIn :: Binary -> Int # digitMaskIn :: Num α => Binary -> α # lastDigitIn :: Bits α => Binary -> α -> Int #
type Rep Binary |
type Rep Binary = D1 (MetaData "Binary" "Text.Printer.Integral" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" 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 |
Methods readsPrec :: Int -> ReadS Octal # readList :: ReadS [Octal] # readPrec :: ReadPrec Octal # readListPrec :: ReadPrec [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 #
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 #
BitSystem Octal |
Methods digitBitsIn :: Octal -> Int # digitMaskIn :: Num α => Octal -> α # lastDigitIn :: Bits α => Octal -> α -> Int #
type Rep Octal |
type Rep Octal = D1 (MetaData "Octal" "Text.Printer.Integral" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" 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 |
Methods compare :: Decimal -> Decimal -> Ordering # (<) :: Decimal -> Decimal -> Bool # (<=) :: Decimal -> Decimal -> Bool # (>) :: Decimal -> Decimal -> Bool # (>=) :: Decimal -> Decimal -> Bool # max :: Decimal -> Decimal -> Decimal # min :: Decimal -> Decimal -> Decimal #
Read Decimal |
Methods readsPrec :: Int -> ReadS Decimal # readList :: ReadS [Decimal] # readPrec :: ReadPrec Decimal # readListPrec :: ReadPrec [Decimal] #
Show Decimal |
Methods showsPrec :: Int -> Decimal -> ShowS # show :: Decimal -> String # showList :: [Decimal] -> ShowS #
Generic Decimal |
Associated Types type Rep Decimal :: * -> * # Methods from :: Decimal -> Rep Decimal x # to :: Rep Decimal x -> Decimal #
PositionalSystem Decimal |
Methods 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 |
type Rep Decimal = D1 (MetaData "Decimal" "Text.Printer.Integral" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" False) (C1 (MetaCons "Decimal" PrefixI False) U1)

data Hexadecimal :: * #

The hexadecimal numeral system.

Constructors

Hexadecimal |

Instances

Eq Hexadecimal |
Methods (==) :: Hexadecimal -> Hexadecimal -> Bool # (/=) :: Hexadecimal -> Hexadecimal -> Bool #
Ord Hexadecimal |
Methods compare :: Hexadecimal -> Hexadecimal -> Ordering # (<) :: Hexadecimal -> Hexadecimal -> Bool # (<=) :: Hexadecimal -> Hexadecimal -> Bool # (>) :: Hexadecimal -> Hexadecimal -> Bool # (>=) :: Hexadecimal -> Hexadecimal -> Bool # max :: Hexadecimal -> Hexadecimal -> Hexadecimal # min :: Hexadecimal -> Hexadecimal -> Hexadecimal #
Read Hexadecimal |
Methods readsPrec :: Int -> ReadS Hexadecimal # readList :: ReadS [Hexadecimal] # readPrec :: ReadPrec Hexadecimal # readListPrec :: ReadPrec [Hexadecimal] #
Show Hexadecimal |
Methods showsPrec :: Int -> Hexadecimal -> ShowS # show :: Hexadecimal -> String # showList :: [Hexadecimal] -> ShowS #
Generic Hexadecimal |
Associated Types type Rep Hexadecimal :: * -> * # Methods from :: Hexadecimal -> Rep Hexadecimal x # to :: Rep Hexadecimal x -> Hexadecimal #
PositionalSystem Hexadecimal |
Methods systemName :: Hexadecimal -> String # radixIn :: Num α => Hexadecimal -> α # isDigitIn :: Hexadecimal -> Char -> Bool # isNzDigitIn :: Hexadecimal -> Char -> Bool # fromDigitIn :: Num α => Hexadecimal -> Char -> Maybe α # fromNzDigitIn :: Num α => Hexadecimal -> Char -> Maybe α # unsafeFromDigitIn :: Num α => Hexadecimal -> Char -> α # intToDigitIn :: Hexadecimal -> Int -> Char # printDigitIn :: Printer p => Hexadecimal -> Char -> p # printZeroIn :: Printer p => Hexadecimal -> p #
BitSystem Hexadecimal |
Methods digitBitsIn :: Hexadecimal -> Int # digitMaskIn :: Num α => Hexadecimal -> α # lastDigitIn :: Bits α => Hexadecimal -> α -> Int #
type Rep Hexadecimal |
type Rep Hexadecimal = D1 (MetaData "Hexadecimal" "Text.Printer.Integral" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" False) (C1 (MetaCons "Hexadecimal" 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 |
Methods readsPrec :: Int -> ReadS UpHex # readList :: ReadS [UpHex] # readPrec :: ReadPrec UpHex # readListPrec :: ReadPrec [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 #
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 #
BitSystem UpHex |
Methods digitBitsIn :: UpHex -> Int # digitMaskIn :: Num α => UpHex -> α # lastDigitIn :: Bits α => UpHex -> α -> Int #
type Rep UpHex |
type Rep UpHex = D1 (MetaData "UpHex" "Text.Printer.Integral" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" False) (C1 (MetaCons "UpHex" 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 |
Methods compare :: LowHex -> LowHex -> Ordering # (<) :: LowHex -> LowHex -> Bool # (<=) :: LowHex -> LowHex -> Bool # (>) :: LowHex -> LowHex -> Bool # (>=) :: LowHex -> LowHex -> Bool # max :: LowHex -> LowHex -> LowHex # min :: LowHex -> LowHex -> LowHex #
Read LowHex |
Methods readsPrec :: Int -> ReadS LowHex # readList :: ReadS [LowHex] # readPrec :: ReadPrec LowHex # readListPrec :: ReadPrec [LowHex] #
Show LowHex |
Methods showsPrec :: Int -> LowHex -> ShowS # show :: LowHex -> String # showList :: [LowHex] -> ShowS #
Generic LowHex |
Associated Types type Rep LowHex :: * -> * # Methods from :: LowHex -> Rep LowHex x # to :: Rep LowHex x -> LowHex #
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 #
BitSystem LowHex |
Methods digitBitsIn :: LowHex -> Int # digitMaskIn :: Num α => LowHex -> α # lastDigitIn :: Bits α => LowHex -> α -> Int #
type Rep LowHex |
type Rep LowHex = D1 (MetaData "LowHex" "Text.Printer.Integral" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" False) (C1 (MetaCons "LowHex" PrefixI False) U1)

# Sign

data Sign #

Sign of a number.

Constructors

NonNegative |
NonPositive |

Instances

Eq Sign # |
Methods (==) :: Sign -> Sign -> Bool # (/=) :: Sign -> Sign -> Bool #
Read Sign # |
Methods readsPrec :: Int -> ReadS Sign # readList :: ReadS [Sign] # readPrec :: ReadPrec Sign # readListPrec :: ReadPrec [Sign] #
Show Sign # |
Methods showsPrec :: Int -> Sign -> ShowS # show :: Sign -> String # showList :: [Sign] -> ShowS #

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

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

optMinus :: CharParsing μ => μ Sign #

Optional minus sign.

optSign :: CharParsing μ => μ Sign #

Optional minus or plus sign.

# Optionality characteristic

data Optional :: * #

Optionality characteristic.

Constructors

Optional |
Required |

Instances

Bounded Optional |
Methods minBound :: Optional # maxBound :: Optional #
Enum Optional |
Methods succ :: Optional -> Optional # pred :: Optional -> Optional # toEnum :: Int -> Optional # fromEnum :: Optional -> Int # enumFrom :: Optional -> [Optional] # enumFromThen :: Optional -> Optional -> [Optional] # enumFromTo :: Optional -> Optional -> [Optional] # enumFromThenTo :: Optional -> Optional -> Optional -> [Optional] #
Eq Optional |
Methods (==) :: Optional -> Optional -> Bool # (/=) :: Optional -> Optional -> Bool #
Ord Optional |
Methods compare :: Optional -> Optional -> Ordering # (<) :: Optional -> Optional -> Bool # (<=) :: Optional -> Optional -> Bool # (>) :: Optional -> Optional -> Bool # (>=) :: Optional -> Optional -> Bool # max :: Optional -> Optional -> Optional # min :: Optional -> Optional -> Optional #
Read Optional |
Methods readsPrec :: Int -> ReadS Optional # readList :: ReadS [Optional] # readPrec :: ReadPrec Optional # readListPrec :: ReadPrec [Optional] #
Show Optional |
Methods showsPrec :: Int -> Optional -> ShowS # show :: Optional -> String # showList :: [Optional] -> ShowS #
Ix Optional |
Methods range :: (Optional, Optional) -> [Optional] # index :: (Optional, Optional) -> Optional -> Int # unsafeIndex :: (Optional, Optional) -> Optional -> Int inRange :: (Optional, Optional) -> Optional -> Bool # rangeSize :: (Optional, Optional) -> Int # unsafeRangeSize :: (Optional, Optional) -> Int
Generic Optional |
Associated Types type Rep Optional :: * -> * # Methods from :: Optional -> Rep Optional x # to :: Rep Optional x -> Optional #
type Rep Optional |
type Rep Optional = D1 (MetaData "Optional" "Text.Printer.Fractional" "text-printer-0.5-403cGoe6c08KytxWNU4hTL" False) ((:+:) (C1 (MetaCons "Optional" PrefixI False) U1) (C1 (MetaCons "Required" PrefixI False) U1))

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 μ) => μ Optional #

Accept a slash and return `Required`. Otherwise return `Optional`.

fraction' #

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 μ) => μ α #

A shorthand for `fraction'` `optMinus` `Decimal` `optSlash`.

# s-fraction parsers

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

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

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

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

fractional' #

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 μ) => μ α #

Decimal fraction parser.