text-0.9.1.0: An efficient packed Unicode text type.

PortabilityGHC
Stabilityexperimental
Maintainerbos@serpentine.com, rtomharper@googlemail.com, duncan@haskell.org

Data.Text.Lazy.Read

Description

Functions used frequently when reading textual data.

Synopsis

Documentation

type Reader a = Text -> Either String (a, Text)Source

Read some text, and if the read succeeds, return its value and the remaining text.

decimal :: Integral a => Reader aSource

Read a decimal integer.

This function does not handle leading sign characters. If you need to handle signed input, use signed decimal.

hexadecimal :: Integral a => Reader aSource

Read a hexadecimal number, with optional leading "0x". This function is case insensitive.

This function does not handle leading sign characters. If you need to handle signed input, use signed hexadecimal.

signed :: Num a => Reader a -> Reader aSource

Read a leading sign character ('-' or '+') and apply it to the result of applying the given reader.

rational :: RealFloat a => Reader aSource

Read a rational number.

This function accepts an optional leading sign character.

double :: Reader DoubleSource

Read a rational number.

This function accepts an optional leading sign character.

Note: This function is almost ten times faster than rational, but is slightly less accurate.

The Double type supports about 16 decimal places of accuracy. For 94.2% of numbers, this function and rational give identical results, but for the remaining 5.8%, this function loses precision around the 15th decimal place. For 0.001% of numbers, this function will lose precision at the 13th or 14th decimal place.