There have been some interesting papers and talks about approaches to handling i/o using left folds recently.

First was the galois tech talk about a safe and efficient i/o interface in Haskell using left fold enumerators. PDF slides are here. The example web server, Hyena, is available on github.

Oleg Kiselyov then gave a talk at DEFUN about using left folds for web servers. The slides and source for the talk are available at Oleg's site in the Haskell Iteratee I/O section.

We explain input processing with left-fold enumerator, using as an example HTTP request processing in Haskell. The approach is general and applies to processing data from various collections, from in-memory data structures to databases, files, sockets, etc. Our approach differs in: permitting incremental processing; i/o interleaving comes by default; we shall see an example of i/o multiplexing with no need for threads and related locking and synchronization. Unlike lazy IO, our approach is correct. There is not even hint of UnsafePerformIO. Unlike Handle-based IO, accessing a disposed resource like a closed handle is just impossible in our approach. Our approach has some other nice properties, permitting composing streams and stream processors. One can use the same processor to handle several streams one after another. Or use two processors to process parts of the same source. One can combine processors vertically, which is very useful when one stream is embedded (chunk-encoded, escaped, UTF8-encoded) into another. Enumerators and iteratees, which generalize fold, have nice algebraic properties. But we won't talk about them.

Interesting weekend reading!