GHC is indeed buggy. Its implementation of Numeric.readSigned
uses the following:
read'' r = do
(str,s) <- lex r
(n,"") <- readPos str
return (n,s)
The lex
call will try to parse any lexeme, and this means that for “7e7” it yields [("7e7", "")]
, because “7e7” is a whole lexeme for a floating point literal. Then it tries to get a complete parse out of readPos
, which in this case is an argument for which Numeric.readDec
was passed in, and readDec
will yield, correctly, [(7, "e7")]
for the string “7e7”. That fails pattern matching against (n, "")
, and ends up as []
.
I think it should be simply as follows:
read'' = readPos