我有这个函数,它需要一个字符串列表和一个字符串,然后返回每个列表中所有元素的列表,其中包含传递的字符串但没有传递的字符串。
myfilter([["a","b"],["c","d"],["e","a","x"]], "a") -> ["b","e","x"]
fun myfilter(list : string list list, s : string) =
case list of
[] => []
|xs::xs' => case all_except_option(s, xs) of (* helper function that does it for a string and a list of strings *)
NONE => []
|SOME n => if n = xs
then myfilter(xs',s)
else n@myfilter(xs',s)
现在,正如您所见,这是一个递归函数,我想将其转换为尾递归函数。我熟悉尾递归的示例,但我看不到如何在上面的函数中做到这一点