[Haskell-cafe] Parsing floating point numbers

Jonathan Cast jonathanccast at fastmail.fm
Sun Mar 8 20:39:15 EDT 2009

On Sun, 2009-03-08 at 19:34 -0500, Bjorn Buckwalter wrote:
> Hi all,
> 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). While I've worked around these shortcomings in the past
> I feel that I am reinventing the wheel as surely I am not the only to
> run into these limitations. How do you parse your floats? Can you
> recommend a parsing library that handles them solidly?
> (For my current needs the formats accepted by "read" are sufficient,
> but I want reasonable error handling (Maybe or Either) instead of an
> exception on bad inputs.)

  fmap fst . listToMaybe . reads


More information about the Haskell-Cafe mailing list