[英]What kinds of recursions are used in the definitions of `foldr` and `foldl`?
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f v [] = v
foldr f v (x:xs) = f x (foldr f v xs)
and和
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl f v [] = v
foldl f v (x:xs) = foldl f (f v x) xs
seem to use different kinds of recursions.似乎使用不同种类的递归。
What kinds of recursions are used in the definitions of foldr
and foldl
? foldr
和foldl
的定义中使用了哪些递归?
Thanks.谢谢。
foldl
uses tail recursion. foldl
使用尾递归。
foldr
uses guarded recursion , the recursion being guarded by f
's laziness (if any). foldr
使用受保护的递归,递归由f
的懒惰(如果有)保护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.