Sunday, February 8, 2009

Thoughts on Ocaml

I'm interviewing with a financial company in Manhattan. The position requires wearing many hats, but it's mostly administration. However, I will be doing a little bit of coding, mostly in the basics (shell, Perl, Python) but also in Ocaml. So I spent the weekend writing two programs in Ocaml based on the problems listed over on Project Euler, numbers 8 and 18 to be specific. This was my first foray into functional programing. I must say I like the paradigm although Ocaml itself leaves something to be desired.

Functional programming treats functions differently than in imperative programing, i.e. "normal" programming. In FP, functions are treated more like mathematical functions, so it is well-suited for some of the problems over on Project Euler. Not everything can be done in a non-imperative way (circular data structures, for example) but it is a good tool to have in your developer's tool box. I was pleased to see that Perl is considered a good functional language, so this weekend's exercise will definitely have an effect on my usual coding style.

Ocaml itself, well, I dunno. It's a relatively young language, started in 1998, so it doesn't have a lot of libraries or even tools; I couldn't find a decent IDE that was being actively developed. Now, normally, un*x/Linux is my IDE (Vim, make, etc.) but I do like to use a graphical IDE every now and then (my current fave is Eclipse) especially when learning a new language/framework.

Since I code quite a bit in Perl, I'm used to using Vim and the internal Perl debugger, a paradigm that Ocaml fits into very well, but the Ocaml debugger needs some work. In the last program I wrote, it kept telling me I had a syntax error on blank lines and even on a line after the end-of-file.

I think I'll go learn Scheme to learn more about functional programing and, of course, Perl.

1 comment:

  1. For a great view on functional programming in Perl, I highly recommend Higher-Order Perl by Mark Dominus: http://www.amazon.com/Higher-Order-Perl-Transforming-Programs/dp/1558607013/. I don't own it, as I don't like Perl in general, but I spent a good amount of time reading it in a bookstore, and have read some of his articles and interviews. Looks terrific. For Perl.

    ReplyDelete