如何读取使用Haskell以指数形式编写的整数?

Fop*_*tin 5 haskell ghci

读取以十进制形式写的整数非常简单:

Prelude> read "1000000000" :: Int
1000000000
Run Code Online (Sandbox Code Playgroud)

但是如何读取以指数形式编写的整数?

Prelude> read "10e+9" :: Int
*** Exception: Prelude.read: no parse
Run Code Online (Sandbox Code Playgroud)

是否有一个函数Prelude要做,或者我们需要解析表达式?

谢谢你的回复.

Mat*_*ick 2

根据字符串的具体格式,您可以将read其转换为浮点类型:

> read "10e+9" :: Double
1.0e10
Run Code Online (Sandbox Code Playgroud)

然后转换为整数类型——我建议Integer而不是Int

> floor (read "10e+9" :: Double) :: Integer
10000000000
Run Code Online (Sandbox Code Playgroud)