5 ms·
What's wrong with accumulators? They are useful for transforming head-recursive code into tail-recursive code. Granted, accumulators can't really improve code
by jganetsk 18y ago
What's wrong with accumulators? They are useful for transforming head-recursive code into tail-recursive code.
Granted, accumulators can't really improve code that traverses trees. But for code that traverses lists, like zip... accumulators can be useful. Also, the added complexity isn't too bad.
- silentbicycle 18y agoIn Okasaki's _Purely Functional Data Structures_, he adds an accumulator variable to the binary (and RB, etc.) tree membership test as an optimization, because it turns the test from up to 2*depth time to constant depth+1 time. (It's exercise 2.2.) I suspect what the post meant was that while accumulators certainly have their benefits, reflexively using them everywhere is probably a sign that you don't really understand them.