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.

tempusfugit (144) [Avatar] Offline
Chapter 3 pp.75 - 77

SumList (p.75) and MultiplyList (p.77) follow the pattern:

op(hn, op(hn-1, op(hn-2, ... )))

e.g.: (1 + (2 + (3 + (4 + (5 + 0)))))

AggregateList (p.77) on the other hand implements

op( op( op( ... , hn-2), hn-1), hn)

e.g.: (((((0 + 5) + 4) + 3) + 2) + 1)

In effect AggregateList is performing a left fold on the reversed list.

Changing AggregateList's (p.77)

return op(rest, list.Head);


return op(list.Head, rest);

will bring it in line with SumList and MultiplyList (and a right fold in general).

Edit: Apparently aggregateList (p.79) has the same issue.