这是我用sml写的计算调和和的代码。我基本上想要计算实数,因为对于整数,所有的计算结果都是0(没有任何用处)。但是这段代码给出了错误。
试验1:
if y<x then 0
else f(x,y-1)+ 1/y;错误:
Elaboration failed: Type clash. Functions of type "real * real → real" cannot take an argument of type "int * int": Cannot merge "int" and "real".试验2:
if y<x then 0
else f(real(x),y-1)+ 1/y;错误:
Elaboration failed: "real" is not a constructor.即使用0.0替换0也不起作用。请帮帮忙。
发布于 2021-02-15 22:25:10
我得到了我的问题的答案。我们基本上需要使用
if y<x then 0.0
else f(x,y-1)+ 1.0/real(y);因为我们函数的类型是(int*int)->real
https://stackoverflow.com/questions/66209519
复制相似问题