How is foldl lazy?

前端 未结 4 2461
星月不相逢
星月不相逢 2021-02-19 16:33

There are lots of good questions and answers about foldl, foldr, and foldl\' in Haskell.

So now I know that:
1) foldl<

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 17:24

    The short answer is that in foldl f, it's not necessarily the case that f is strict, so it might be too eager to reduce the thunks up front. However, in practice it usually is, so you nearly always want to be using foldl'.

    I wrote a more in-depth explanation of how the evaluation order of foldl and foldl' works on another question. It's rather long but I think it should clarify things a bit for you.

提交回复
热议问题