简体   繁体   English

`foldr` 和 `foldl` 的定义中使用了哪些类型的递归?

[英]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 ? foldrfoldl的定义中使用了哪些递归?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM