Proposal (base): Add new Exp constructor to Text.Read.Lex.Lexeme

Simon Marlow marlowsd at
Mon Dec 12 10:51:40 CET 2011

On 09/12/2011 08:01, Gracjan Polak wrote:
> Core of proposal: Add
> data Lexeme
>    ...
>    | Exp Integer Integer -- ^ Floating point literal in exponential form a*10^b
> So that numbers in exponential notation can be represented directly.
> Rationale:
> Currently when parsing 12e1000000000000 it is at some point represented as
> Rational, and of course does not fit in memory. Later on this Rational is
> converted to Integer or Int8 or Float or Double, but we never get to that point.
> This uncovers three bugs:
> 1) 12e12 :: Integer should not parse per Report
> 2) 12eXXX :: Double should parse, for large values of XXX should give +Infinity,
> for large negative values of XXX should give +0.0
> 3) integer-gmp (and/or integer-simple) is not immune to allocation errors and
> does 'Segmentation violation' or 'Bus error' (sometimes correctly throws 'Out of
> memory' though)
> My proposal addresses 1) and 2) as I needed to change public interface of
> Text.Read.Lex to get it fixed.
> More info and a patch in trac:
> As reading numbers is core for web (for example HTTP headers, URLs, JSON etc)
> this is a security issue.
> As this is security issue I'm tempted to insist this goes into GHC 7.4. What do
> you think?

Ok by me, though I'm not familiar with the details of 
Text.Read.Lex.Lexeme.  I think it's an "internal" API of sorts, since it 
was added to implement Text.Read.lex.

I wonder why integer-gmp crashes when trying to allocate too much... 
sounds like we need to look into that - could you make a ticket if there 
isn't already one?


More information about the Libraries mailing list