there's a notion that I first encountered in a course on Clean, though I suppose it doesn't originate there, of writing functions that would return a list in CPS instead, in the sense that one passes a list to be used instead of the empty list.
That allows one to avoid the quadratic runtime of continually generating intermediate lists that one needs to append together.
Today I realized that this idea is also connected to making a function tail-recursive, as well as to generalizing an induction hypothesis. I'm not sure these three notions are related outside this context, but still found it a neat observation.
@cxandru Is this similar to using “difference lists” in Haskell? (See the dlist package.)
@Joshua yes! Thanks for the reference!
@cxandru For other types there are “Builder” types which are somewhat similar (and also a known pattern in other languages).
More abstractly, I’ve seen this being related to #yoneda or #coyoneda. But I’ve never really understood that.