【发布时间】:2015-08-17 09:59:38
【问题描述】:
我正在尝试在 SML 中编写一个函数,该函数将返回列表元素的子序列,以及列表其余元素的序列。 所以,我的功能是
fun subseq (left,right,0) = (left,right) |
subseq (left,h::t,len) =
let
val (left,right) = subseq ([],t,len-1)
in
(h::left,right)
end;
fun subseqMain (mainList, length) = subseq ([],mainList,length);
我的问题是如何在不使用 @ 运算符的情况下,通过将其转换为尾递归函数来提高此函数的效率。
感谢您的宝贵时间!
【问题讨论】:
-
explicating the stack,任何语言。
标签: recursion sml tail-recursion