[Haskell-cafe] Parsing floating point numbers

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Mon Mar 9 06:45:01 EDT 2009

Bjorn Buckwalter <bjorn.buckwalter at gmail.com> wrote:

> What is your preferred method of parsing floating point numbers (from
> String to Float/Double)? Parsec it seems only does positive floats out
> of the box and PolyParse requires the float to be on scientific form
> (exponential).

Thanks for the bug report.  Polyparse is now fixed.  New version
(polyparse-1.3) available on Hackage.

And my apologies.  This was purely an oversight - the real-world
use-case at the time I wrote the code for Text.Parse.parseFloat was
entirely dependent on scientific notation, and I neglected the more
usual case.

For those looking for a template to implement textual float-parsing that
is faster (or has better error messages) than the H'98 Read class, feel
free to translate this code into your own parser combinator library of


(Note that the actual instances of the Parse class for Float and Double
use "parseSigned parseFloat" to deal with non-positive numbers.)


More information about the Haskell-Cafe mailing list