看这里:https://hackage.haskell.org/package/scientific
在这里:numbers
我希望能在科学表示法中以字符串形式输入一个数字
Prelude Data.Scientific> read "1e100" :: Scientific
1.0e100并转换成整数,如下所示:
Prelude Data.Scientific> (read "1e100" :: Scientific ) :: Int
<interactive>:7:2: error:
• Couldn't match expected type ‘Int’ with actual type ‘Scientific’
• In the expression: (read "1e100" :: Scientific) :: Int
In an equation for ‘it’: it = (read "1e100" :: Scientific) :: Int这似乎行不通。如何将我的科学类型转换为整数?
发布于 2018-10-03 06:02:03
您希望使用toUnboundedInteger (或者toBoundedInteger,我不确定绑定10^e指的是什么)。签名是:
toUnboundedInteger :: Scientific -> Maybe Integer因此,非正式地,函数检查Scientific参数是否实际上是一个整数(例如,它可能是一个浮点数)。如果它是一个浮点数,返回的结果是Nothing,否则它就是Just,您期望的整数。
https://stackoverflow.com/questions/52620391
复制相似问题