Hi folks,
Thanks for all your interesting questions last night. I've attached the corrected presentation (someone pointed out an error in the code).
A correction is in order. We talked about a limitation of the declarative queues that I presented: that you could not share queues as parts of other queues. For example, with lists, you can easily have two different lists that share the same tail. With a queue, you might like to fork it into two versions, adding a different element to each version. This is called a persistent queue. You'd like to have a persistent queue without taking an O(n) performance hit for a worst-case operation.
I said it wasn't possible to do this efficiently, but that's incorrect. It's possible to implement declarative persistent queues with O(1) worst-case operation. The CTM book explains how to create persistent queues with an O(log n) complexity, by doing occasional copying of the queue. It leaves the O(1) case as an exercise (Ch. 4, Ex. 20). I've attached my solution.
- Lyle