Nleyten@900: being CDuced


I spent a few weeks working outside the Subversion repository, mostly experimenting with OCaml, PG'OCaml, Ocsigen, CDuce, and OCamlDuce. But development has now returned back into the repository; the reason being that I've developed the first backend module: an OCamlDuce-based library to fetch and parse book metadata using the Amazon Web Services API.

There's an old computer science aphorism that says that "those who don't know Unix are doomed to reinvent it; poorly". It's a timeless truth that applies to multiple situations, not just to Unix. A good example can be found in the present mess surrounding Web API's. Nowadays, most of them tend to use either SOAP or some REST protocol. The problem is that either solution is worse than good old SUN RPC. So why aren't people using SUN RPC instead? I have some theories. It's either because a) most programmers have got this weird idea that XML is some kind of god that should be worshiped not matter what, and therefore, all communication on the Internet must use some XML-based protocol — which SUN RPC is not; b) Microsoft does not like SUN, and has therefore pushed SOAP instead of SUN RPC just out of spite; or c) people are stupid. All options are likely right.

Anyway, since I am forced to either use the very broken SOAP protocol (which I refuse to do), or to use REST and take care of parsing the XML response, I figured that time was ripe to learn CDuce/OCamlDuce. Now, CDuce (pronounced "seduce" — what do you want; it comes from France) is a language especially designed to handle XML documents. XML elements and tags are part of the native types of the language, and being strongly-typed, you get those warm fuzzy feelings that come from type-safety. Anyway, if you ever have to deal with SAX/DOM parsers, or if your application makes heavy use of XML, do yourself a favour and check out CDuce.

CDuce was designed to integrate very well with OCaml. Basically, you can compile a CDuce module in a binary compatible way with OCaml modules. There is also a fairly straightforward mapping between the types of the two languages. OCamlDuce takes this integration one step further: think of it as a way to embed CDuce expressions inside normal OCaml programmes. The OCaml language is thus extended with a powerful syntax to handle XML documents as if they were native to the language.

As for the 900th revision itself, it says "Converted CDuce sources to OCamlDuce", reflecting the fact that though the first versions of the library were using CDuce + an OCaml glue module, later I've converted them to OCamlDuce code, thus merging everything into a single module.

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.