foldl is tail recursive, so how come foldr runs faster than foldl?

后端 未结 7 1403
無奈伤痛
無奈伤痛 2020-11-27 10:42

I wanted to test foldl vs foldr. From what I\'ve seen you should use foldl over foldr when ever you can due to tail reccursion optimization.

This makes sense. Howeve

7条回答
  •  鱼传尺愫
    2020-11-27 11:22

    Neither foldl nor foldr is tail optimized. It is only foldl'.

    But in your case using ++ with foldl' is not good idea because successive evaluation of ++ will cause traversing growing accumulator again and again.

提交回复
热议问题