the Differences of Fold-left and Fold-right

来源:互联网 发布:淘宝模特保持身材 编辑:程序博客网 时间:2024/06/06 17:01

Fold-left and Fold-right are two frequently used procedures when processing a list. They have the same declarations, but they have different implementations.

 

The declarations of Fold-left and Fold-right are followed. They combines all of the elements of the-list using the binary operation procedure. If the procedure obeys the associative-law, the fold-right and fold-left will get the same result. If (procedure a (procedure b c)) is equivalent to (procedure (procedure a b) c), then we can say the procedure obeys the associative-law. 

 

 

Even though fold-left and fold-right behave the same in some cases, the internal calculating process are not the same for such cases. We should know the difference. In essence, fold-left is a iterative process, whereas fold-right is a recursive process.

 

The mimic implementations for fold-left and fold-right are followed. It is not difficult to make the conclusion.

 

 

原创粉丝点击