The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

v.matveev (4) [Avatar] Offline
Fold function given in listing 6.22 seems to be right but not left as it is named. Order of computations is the following:
f ( f ( f (eN init) eN-1) ... e0)
but it should be
f ((f (f (init e0)) e1) ... eN)

so function may look like this
let rec fold_left f init = function
| [] -> init
| hd::tl -> fold_left f (f init hd) tl
Tomas Petricek (160) [Avatar] Offline
Re: foldLeft sample (listing 6,22)
thanks for reporting this - you're of course correct. I've fixed the issue just now. The problem is that when showing folding in chapter 3, it is more natural to show fold right, so I have to change the source code in chapter 6 to show fold left.