Skip to content

Exponential literal syntax is dangerous

Try (on your own risk)

Prelude> 1e1111111111111111111 :: Integer

in GHCi. (I had to kill the GHCi with kill -9 when it used around 5G of memory, luckily the memory usage didn't grow too fast).

This is dangerous.


But i'd expect

Prelude> 1e1111111111111111111 :: Double
Prelude> 1e1111111111111111111 :: Scientific

to work, (Double overflow to Infinity, Scientific is fine representing that number)

Scientific.scientific 1 1111111111111111111
1.0e1111111111111111111

(in fact even bigger exponents, but for now the exponent is just Int, not Integer).

Fixing this issue would require some new mechanism for desugaring from scientific notation. But until that is invented, GHC should probably refuse to allocate gigabyte large integers.

Edited by Oleg Grenrus
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information