picoparsec-0.1.2.3: Fast combinator parsing for bytestrings and text

CopyrightBryan O'Sullivan 2011 Mario Blažević <blamario@yahoo.com> 2014
LicenseBSD3
MaintainerMario Blažević
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Data.Picoparsec.Number

Contents

Description

This module is deprecated, and both the module and Number type will be removed in the next major release. Use the scientific package and the Scientific type instead.

A simple number type, useful for parsing both exact and inexact quantities without losing much precision.

Synopsis

Documentation

data Number #

A numeric type that can represent integers accurately, and floating point numbers to the precision of a Double.

Constructors

I !Integer 
D !Double 

Instances

Eq Number # 

Methods

(==) :: Number -> Number -> Bool #

(/=) :: Number -> Number -> Bool #

Fractional Number # 
Data Number # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Number -> c Number #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Number #

toConstr :: Number -> Constr #

dataTypeOf :: Number -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Number) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Number) #

gmapT :: (forall b. Data b => b -> b) -> Number -> Number #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Number -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Number -> r #

gmapQ :: (forall d. Data d => d -> u) -> Number -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Number -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Number -> m Number #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Number -> m Number #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Number -> m Number #

Num Number # 
Ord Number # 
Real Number # 
RealFrac Number # 

Methods

properFraction :: Integral b => Number -> (b, Number) #

truncate :: Integral b => Number -> b #

round :: Integral b => Number -> b #

ceiling :: Integral b => Number -> b #

floor :: Integral b => Number -> b #

Show Number # 
NFData Number # 

Methods

rnf :: Number -> () #

Numeric parsers

decimal :: (TextualMonoid t, Integral a) => Parser t a #

Parse and decode an unsigned decimal number.

hexadecimal :: (TextualMonoid t, Integral a, Bits a) => Parser t a #

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.

signed :: (TextualMonoid t, Num a) => Parser t a -> Parser t a #

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

double :: TextualMonoid t => Parser t Double #

Parse a rational number.

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

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.

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

number :: TextualMonoid t => Parser t Number #

Parse a number, attempting to preserve both speed and precision.

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

Note: This function is almost ten times faster than rational. On integral inputs, it gives perfectly accurate answers, and on floating point inputs, it is slightly less accurate than rational.

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

rational :: (TextualMonoid t, Fractional a) => Parser t a #

Parse a rational number.

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:

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

Examples with behaviour identical to read:

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

Examples of differences from read:

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

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

scientific :: TextualMonoid t => Parser t Scientific #

Parse a scientific number.

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