@@ -475,6 +475,24 @@ signed p = (negate <$> (char8 '-' *> p))
475475 <|> (char8 '+' *> p)
476476 <|> p
477477
478+-- | Parse a rational number.
479+--
480+-- The syntax accepted by this parser is the same as for 'double'.
481+--
482+-- /Note/: this parser is not safe for use with inputs from untrusted
483+-- sources. An input with a suitably large exponent such as
484+-- @"1e1000000000"@ will cause a huge 'Integer' to be allocated,
485+-- resulting in what is effectively a denial-of-service attack.
486+--
487+-- In most cases, it is better to use 'double' or 'scientific'
488+-- instead.
489+rational :: Fractional a => Parser a
490+{-# SPECIALIZE rational :: Parser Double #-}
491+{-# SPECIALIZE rational :: Parser Float #-}
492+{-# SPECIALIZE rational :: Parser Rational #-}
493+{-# SPECIALIZE rational :: Parser Scientific #-}
494+rational = scientifically realToFrac
495+
478496-- | Parse a rational number.
479497--
480498-- This parser accepts an optional leading sign character, followed by
@@ -502,28 +520,12 @@ signed p = (negate <$> (char8 '-' *> p))
502520--
503521-- This function does not accept string representations of \"NaN\" or
504522-- \"Infinity\".
505−rational :: Fractional a => Parser a
506−{-# SPECIALIZE rational :: Parser Double #-}
507−{-# SPECIALIZE rational :: Parser Float #-}
508−{-# SPECIALIZE rational :: Parser Rational #-}
509−{-# SPECIALIZE rational :: Parser Scientific #-}
510−rational = scientifically realToFrac
511−
512−-- | Parse a rational number.
513−--
514−-- The syntax accepted by this parser is the same as for 'rational'.
515−--
516−-- This function does not accept string representations of \"NaN\" or
517−-- \"Infinity\".
518523double :: Parser Double
519524double = scientifically Sci.toRealFloat
520525
521526-- | Parse a number, attempting to preserve both speed and precision.
522527--
523−-- The syntax accepted by this parser is the same as for 'rational'.
524−--
525− -- This function does not accept string representations of \"NaN\" or
526− -- \"Infinity\".
528+-- The syntax accepted by this parser is the same as for 'double'.
527529number :: Parser Number
528530number = scientifically $ \s ->
529531 let e = Sci.base10Exponent s
@@ -535,7 +537,7 @@ number = scientifically $ \s ->
535537
536538-- | Parse a scientific number.
537539--
538−-- The syntax accepted by this parser is the same as for 'rational'.
540+-- The syntax accepted by this parser is the same as for 'double'.
539541scientific :: Parser Scientific
540542scientific = scientifically id
541543