Tuesday, July 08, 2008

Lingual Dexterity - The OCaml Development Environment

All the tools and setups that I mention in this post are on the Mac OS, so it'll be a pretty straight forward port if you're using a Linux platform. Alternately if you are on Windows, you're in good shape if you're running Cygwin.

I've found a pretty good post here on setting up an OCaml development environment on the Mac OS. One thing that this post leaves out is that you'll need to make sure you install the Makefile Textmate Bundle.

Using the Interpreter


Since it's mostly a functional language, you find yourself using the interpreter quite a bit in order to test out small chunks of code or even start getting warmed up to the language. You'll immediately notice that your up/down/back/forward keys are useless. In order to get those buttons to do what you're used to, you'll have to install ledit. ledit is a line editor that gives you Emacs like control characters. Once you get it installed, you can open terminal and type
ledit ocaml

and you'll be running the OCaml interpreter through ledit. The instructions I refer to above have you install this, so if you fallow those closely, you'll be in good shape already.

One option for your edit/compile/run cycle is to write your code in a file, then use that file in the interpreter, to exercise your functions. To do this, you'll need to use the "#use" instruction with in the interpreter. In terminal start up OCaml with
ledit ocaml

then this to import your file (path is relative)
#use "myOcaml.ml

Aside from unit testing (which will be it's own post), this is the fastest way I've found to develop in the OCaml environment.

The IDE


OCaml is really one of those "notepad" languages (are there any other "non-notepad" languages other than VB, C# and Java?). As with lots of other "notepad" languages, there's Eclipse plugins, Emacs clones, VI(M) files and TextMate bundles. I'm a big fan of TextMate and have done most of my work in OCaml using it. There's a bundle for OCaml that I've been using that's been working fairly well for me for some debugging, but doesn't work all that well for unit testing (I guess there's an idea for a bundle with unit testing support.

What I find myself doing most of the time is editing the file in TextMate and then navigationg to the makefile tab in TextMate (option+command+arrow), building (command+r), then switching to my terminal window to execute the unit tests.

In the next post, I'll go over how to setup and execute unit tests.

Again, if there's anyone else out there who has feedback on this setup, I'd love to hear it. As I said, I'm by no means an expert, and any productivity enhancing tips you all have, would be great to hear.