OCaml streams tutorial

I wrote a tutorial on the Stream module for the Objective CAML Tutorial wiki. It’s got a lot of code that I’ve been sitting on for almost two years, so it feels good to finally get it up on the interwebs where a hard drive crash can’t hurt it.

The Stream module is not very well known, and until now has had almost no documentation. I found out a lot by studying the source while working on the PLEAC project. I also got some ideas from Raymond Hettinger’s excellent work on Python’s itertools module; Python’s generators are very similar to OCaml’s streams.

I hope to find the time to also write a tutorial on camlp4 stream expressions, which use the Stream module to implement syntax sugar that makes stream processing and parsing much more concise.

spoomusic.com redesign for 2008

I launched the new WordPress-driven spoomusic.com website this month, which was a fun and rewarding experience. The old site was written without a database, using the filesystem for nearly everything. As crazy as it sounds, I think this was exactly the right thing to do at the time because the content was primarily MP3s and images. In addition, since the design was about as simple as it could possibly be, it was rather straightforward to bulk import all of the content (news, interviews, album text, etc.) using WordPress’s XML-RPC interface. (And I did it in OCaml using my library, xmlrpc-light, so I even had fun doing it!)

There are many advantages to using WordPress that I already enjoy: all albums and other content can get comments, which is a feature I wanted for a long time but never had the energy to write from scratch; albums can now be “drafts”, which is so awesome, since we never get albums right the first time, and it’s nice that the public doesn’t have to endure our accidents; artists can edit their own album content; artists each get their own blog… I could go on…

By the way, I’m writing this using the latest SVN trunk of WordPress, which has a totally redesigned administration interface. It looks like it’s still a work in progress, and I’m not sure what I think of it yet. It sure is different. Try it out sometime.

XmlRpc-Light 0.6 Released

I have released XmlRpc-Light 0.6. XmlRpc-Light is an XmlRpc client and server library written in OCaml. It requires Xml-Light and Ocamlnet 2.

http://code.google.com/p/xmlrpc-light/

This release introduces a new module, XmlRpcDateTime, which provides a date time type (still a tuple of integers), time-zone-aware equality and comparison, XmlRpc-flavored iso-8601 parsing and generation, time zone adjustment, and conversion functions to- and from- Unix float and Unix.tm for both local and UTC times. There is also a handy “now()” function to build a time stamp for the current time. The Unix conversion functions follow the same naming convention as Julien Signoles’ calendar library to ease integration with that package.

I have written a suite of unit tests, based on Maas-Maarten Zeeman’s oUnit framework, which you can run by typing “make test”. These tests cover parsing and generation of XmlRpc values and messages, date-time parsing and arithmetic, and the server’s function call and error handling behavior.

The WordPress example library has been updated to support WordPress 2.3, which now provides UTC date-time values. The interface has been kept mostly the same. It now uses XmlRpcDateTime.t instead of defining a “datetime” type, but this shouldn’t break any code since due to structural typing. The one thing that doesn’t work the same is the “suggest_categories” method, since WordPress has completely changed the structure of its results. Rather than attempt to make any sense of the new result format, which is rather odd, I decided to punt here and just return an XmlRpc.value (variant).

Finally, I have added support for the somewhat controversial “nil” type. Not all servers support this type, and Dave Winer has been known to be adamantly opposed to it, but it has become a de-facto standard and quite a few XmlRpc libraries support it now. If you don’t like it, don’t use it. =)