Sml 大数GCD
我正在尝试创建一个处理非常大的数字的gcd函数。因此,到目前为止我尝试过的任何东西都会导致错误。例如:Sml 大数GCD,sml,greatest-common-divisor,Sml,Greatest Common Divisor,我正在尝试创建一个处理非常大的数字的gcd函数。因此,到目前为止我尝试过的任何东西都会导致错误。例如: fun gcd(a : Int.toLarge, b : Int.toLarge): Int.toLarge = if b = 0 then a else gcd(b, a mod b)` 给我以下错误: Error:unbound type constructor : toLarge in path Int.toLarge 有人能给我一些建议吗,我的计划的其余部分似乎工
fun gcd(a : Int.toLarge, b : Int.toLarge): Int.toLarge =
if b = 0
then a
else gcd(b, a mod b)`
给我以下错误:
Error:unbound type constructor : toLarge in path Int.toLarge
有人能给我一些建议吗,我的计划的其余部分似乎工作得很好。提前谢谢你 您将
Int.toLarge
视为一个类型,但它是一个函数。您要查找的类型是IntInf.int。一个gcd函数看起来是一样的,不管你在其中输入了什么类型的数字;但您可能必须参考另一个模块中的算术运算符
下面是Int.Int类型的gcd函数:
由于SML/NJ的算术运算符重载,因此IntInf.int有一个:
fun gcd (a, 0) = a
| gcd (a, b) = gcd (b, a - b*(a div b))
fun gcd (a, 0) = a : IntInf.int
| gcd (a, b) = gcd (b, a - b*(a div b))