<p dir="ltr">I have undertaken[*] to improve the Read instances for a number of types in base. My primary goal is to make things run faster, and my secondary goal is to make things fail faster. The essence of my approach is to abandon the two-stage lex/parse approach in favor of a single-phase parse-only one. The most natural way to do this makes some parsers more lenient. With GHC's current implementation, given</p>
<p dir="ltr">readsInt :: String -> [(Int, String)]<br>
readsInt = reads</p>
<p dir="ltr">we get</p>
<p dir="ltr">readsInt "12e" = [(12, "e")]<br>
readsInt "12e-" = [(12,"e-")]<br>
readsInt "12e-3" = []<br>
readsInt ('a' : undefined) = undefined</p>
<p dir="ltr">This is because the Read instance for Int calls a general lexer to produce tokens it then interprets. For "12e-3", it reads a fractional token and rejects this as an Int. For 'a': undefined, it attempts to find the undefined end of the token before coming to the obvious conclusion that it's not a number.</p>
<p dir="ltr">For reasons I explain in the ticket, this classical two-phase model is inappropriate for Read--we get all its disadvantages and none of its advantages. The natural improvement makes reading Int around seven times as fast, but it changes the semantics a bit:</p>
<p dir="ltr">readsInt "12e" = [(12, "e")] --same<br>
readsInt "12e-" = [(12,"e-")] --same<br>
readsInt "12e-3" = [12,"e-3"] --more lenient<br>
readsInt ('a' : undefined) = [] --lazier</p>
<p dir="ltr">As I understand it, GHC's current semantics are different from those of the Haskell 98 reference implementation, and mine come closer to the standard. That said, this would be a breaking change, so the CLC's input would be very helpful.</p>
<p dir="ltr">The alternative would be to bend over backwards to approximate the current semantics by looking past the end of an Int to see if it could look fractional. I don't much care for the non-monotone nature of the current semantics, so I don't think we should go to such lengths to preserve them.</p>
<p dir="ltr">[*] <a href="https://ghc.haskell.org/trac/ghc/ticket/12665">https://ghc.haskell.org/trac/ghc/ticket/12665</a></p>