【发布时间】:2016-06-14 17:36:05
【问题描述】:
这是我的任务。
我一直在和一位导师一起研究这个,这就是我们迄今为止想出的。
fun mult(a,b) =
let
val product = 0
in
if (a = 0) then
0
else
while a > 0 do
(
product := product + b;
if (a = 1) then
product
else
a:= a -1
);
end;
; //the function did not run at end;, so we added these two semicolons below
;
这个输出是:
stdIn:102.11-103.6 Error: syntax error: deleting SEMICOLON END SEMICOLON
我在过去 2 周内才被介绍到 SML,但我无法理解它。非常感谢任何帮助。
【问题讨论】:
-
这个练习对我来说没有多大意义——非递归 while 循环版本在任何意义上都“等效于”尾递归方法意味着什么?无论如何——
product := product + b在 SML 中没有意义,因为 int 变量是不可变的。这样的事情需要int ref。你研究过这些吗?
标签: iteration translation sml translate tail-recursion