biginteger - 如何在 SML 中使用 IntInf 或 LargeInt?

标签 biginteger sml

我想通过此链接中的 pow 等函数在 SML 中执行大整数计算:

http://www.standardml.org/Basis/int-inf.html#IntInf:STR:SPEC

但是我怎样才能使用这个“库”呢?


更新:

感谢您的回答。我知道了。我还必须更改打印限制

Control.Print.intinfDepth := 10000;

我为 IntInfs 创建了自己的 pow 函数(并且它有效),如下所示:

fun power 0 = IntInf.toLarge 1
  | power n = IntInf.toLarge 2 * power(n-1);

最佳答案

这取决于您使用的实现方式,但通常您需要使用 Int.toLarge 将 Int 类型转换为 LageInt/InfInf 类型:

(* will be types as an IntInf *)
val aa = 10983298432984329843298432984329843298432987987987432987987987432987
val a = IntInf.pow(aa,10);

(* explicit type as if some other constraint had enforced this*)
val b = 10 : int
val c = Int.toLarge b;

val d = IntInf.pow(c, b);

变量 aa 可能无法在您的解释器中解析。这取决于你使用什么。我已经在 poly 和 mlton 中测试过了。

上面获取类型的地方(由带有 -show-basis 标志的 mlton 给出):

val a: intInf
val aa: intInf
val b: int32
val c: intInf
val d: intInf

关于biginteger - 如何在 SML 中使用 IntInf 或 LargeInt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7807441/

相关文章:

java - 将文本转换为 BigInteger 时的 RSA 实现问题

c# - 如何在 C# 中将 huuuuuge 字符串加载到 BigInteger 中并且不丢失 ASCII 编码

f# - 解释模式匹配与切换

python - Python 与 ML 中的词法作用域

php - PHP 中有 BigInteger 类吗?

javascript - 如何在javascript中处理大数字

java - 如何将 Hibernate 中的 BigInteger 映射到 DB2

sml - 为什么使用这些重载运算符定义函数时不会出错?

functional-programming - SML:基本 Prime 测试

ubuntu - 在 Ubuntu 中使用 SMLNJ 时遇到问题