Thursday, 31 January 2008

Why ocaml and haskell are not for scientists?

Why ocaml and haskell is not for scientists.

I am currently postdoc, soon it will be a year. For my new project I decided to try to use ocaml instead of more traditional environment - Matlab.

But after a year reading documentation, books, trying to implement something, I decided to drop it and keep using matlab. If time permits I would keep an eye on the development of this languages, but I would not use it for scientific calculations in the nearest future.

Here are my points and I want someone to convince my that I am wrong - I would like to be convinced.

1) The choice of ocaml for the project was due to the fact that my new project has a lot of recursive functions and functional languages should handle it better than matlab.

2) Native integer precision on amd 64.

3) Speed.

I was really impressed with demos from the book "OCaml for Scientists" by Jon Harrop, however the price tag was too high, so I ended up getting it through inter library loan for the period 3 weeks. The book is worth reading, it gave me few very good ideas. But!! Most examples from the book are not repeatable. That is not scientific for me.

There is nothing in the book about the versions of the modules used or even OS. (It's actually debian linux)

I installed debian, but I still had a problem repeating examples.

Because 2D figures in the book generated using Mathematica rather than ocaml. Why do you think it has been done this way? Because there is no binding to gnuplot or simular lib for plotting. Actually there is, but it is not stable and has not been updated for a while. I was eagerly waiting for the end of Ocaml Summer Project as visualisation toolkit and mathematical framework looked fairly useful for me. It's already summer project 2008 announced, but the projects from osp2007 still in svn even not pre-alpha.

I think this is one of the major problems with ocaml - you can find very interesting projects or modules, but they mostly abandon, never made it ever as far as beta. And with lack of standards and documentation for modules I spend hours trying to install some necessary modules. As a former unix system administrator, I could install server with something like postfix+dovecot+samba+ldap with maia, but I can't install for example fftw module on linux and on mac os x. I was ready to tear my hair off. I think because ocaml community is small you rarely would find real cross platform modules there.

As a newbie I found it frustrating that I could not repeat completely any ocaml tutorial or book. As soon as you try to move from basic calculation, you are hitting  the wall trying to repeat example from the book or tutorial and getting some obscure message.

With haskell I was lucky enough to get hmatrix working, it does have a proper plotting and matrix manipulation. I even got as far as writing my own haar wavelet and started hennon map. Guess what? Hennon map in haskell is slow. Slower than perl and slower then C. But haskell community larger and more dynamic, possible due to the fact that haskell syntax standard, rather then current 3 styles of ocaml.

And because ocaml and haskell have strong types you will have to convert vector matrix to vector double if you want to plot it or to pass from gsl library to fft or another library.

My conclusion - I don't get paid for rewriting common modules and calculations in different languages. I get paid for inventing new thing, new methods.

Although ocaml and haskell interesting languages, they just not ready for scientific use. I didn't mean computer scientist, who actually get paid for writing software, but for scientists in more general sense - physics, signal processing, image processing. Also having good language is not enough to be useful. Creating compiler is a mandatory exercise for computer science undergraduate.

It is a community, modules and common standards that allow easy adoption of new language.

So far neither ocaml no haskell, not even ruby or python reached the level of perl. I am talking about CPAN. Although python and ruby getting close. So it might be worth trying perl for number crunching or draw back to C++ or C. It worth checking new technologies, but in the end it is a result that is required. Repeatable and published.

Update: After initial post Christophe did a lot of work improving fftw3 with new examples.