【发布时间】:2020-10-02 12:08:28
【问题描述】:
我应该只实现尾递归函数。考虑到在每次调用中我都有三个函数在其中工作以获得答案,这段代码是否是尾递归的?
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' 都是尾递归函数。我确信这一点。
【问题讨论】:
-
如果您确定
anyfunction是尾递归的,那么您的问题是什么? -
所以你确定
anyfunction是尾递归的,而你的问题是anyfunction是否是尾递归?
标签: haskell recursion optimization tail-recursion tail