binary-parsers-0.1.0.0: Extends binary with parsec/attoparsec style parsing combinators.

Copyright Bryan O'Sullivan 2007-2015, Winterland 2016 BSD3 drkoster@qq.com experimental unknown None Haskell2010

Data.Binary.Parser.Numeric

Description

Simple, efficient combinator parsing for numeric values.

Synopsis

# Documentation

hexadecimal :: (Integral a, Bits a) => Get a Source #

Parse and decode an unsigned hexadecimal number. The hex digits 'a' through 'f' may be upper or lower case.

This parser does not accept a leading "0x" string.

decimal :: Integral a => Get a Source #

Parse and decode an unsigned decimal number.

signed :: Num a => Get a -> Get a Source #

Parse a number with an optional leading '+' or '-' sign character.

rational :: Fractional a => Get a Source #

Parse a rational number.

The syntax accepted by this parser is the same as for double.

Note: this parser is not safe for use with inputs from untrusted sources. An input with a suitably large exponent such as "1e1000000000" will cause a huge Integer to be allocated, resulting in what is effectively a denial-of-service attack.

In most cases, it is better to use double or scientific instead.

Parse a rational number and round to Double.

This parser accepts an optional leading sign character, followed by at least one decimal digit. The syntax similar to that accepted by the read function, with the exception that a trailing '.' or 'e' not followed by a number is not consumed.

Examples with behaviour identical to read, if you feed an empty continuation to the first result:

double "3"     == Done 3.0 ""
double "3.1"   == Done 3.1 ""
double "3e4"   == Done 30000.0 ""
double "3.1e4" == Done 31000.0, ""

Examples with behaviour identical to read:

double ".3"    == Fail "input does not start with a digit"
double "e3"    == Fail "input does not start with a digit"

Examples of differences from read:

double "3.foo" == Done 3.0 ".foo"
double "3e"    == Done 3.0 "e"

This function does not accept string representations of "NaN" or "Infinity".

Parse a scientific number.

The syntax accepted by this parser is the same as for double.

scientifically :: (Scientific -> a) -> Get a Source #

Parse a scientific number and convert to result using a user supply function.

The syntax accepted by this parser is the same as for double.