我可以将以下代码称为“尾递归”吗? -Haskell函数

问题描述 投票:-1回答:1

我应该只实现尾递归函数。考虑到每次调用我在其中有三个函数在工作以获取答案,因此该代码尾是否递归?

anyfunction :: (Ord a) => Int -> [a] -> [a] -> [a] -> a
anyfunction n [] ys ws = anyfunction n ws ys ws
anyfunction (-1) (x:xs) ys ws = something x xs
anyfunction n (x:xs) ys ws = anyfunction (n+1) (someotherthing(something x xs) (x:xs) []) (ys ++ [(something x xs)]) ws

请注意:'something'和'someotherthing'都是尾递归函数。我确定。

haskell recursion optimization tail-recursion tail
1个回答
0
投票

anyfunction,定义为尾递归,无论someotherthingsomething是什么。

唯一取决于someotherthingsomething是否为尾部递归的是anyfunction将从尾部调用优化中受益多少。

© www.soinside.com 2019 - 2024. All rights reserved.