It can be tempting when learning a new language to start with basic tutorials and only when some level of mastery has been achieved to try and use it for real work. The drawback with this approach, is that by the time it becomes clear that a particular task you need to solve is very difficult with a particular language, you have already invested a huge amount of time. Consider a language eco-system: syntax, libraries, tools and community are all part of a language and need to be learned in order to become adept.
I find Ocaml an exceptionally impressive piece of software: It bootstraps a very fast native-code compiler using just a C compiler on a variety of platforms, it includes a fast bytecode virtual machine, it has an extensive standard library and it includes a number of extremely useful tools that aren’t necessary included with other minority languages such as a debugger and a profiler. Additionally, although I’ve only been using it a few weeks, I’ve found it a nice language to use. I really like developing with a REPL and I definitely like something about static-typing. I like dynamic typing too and list scheme and perl among languages I enjoy using. Of course, like every language, it has its drawbacks, but are there any deal-breakers?
As a software developer, I (usually) much prefer to use good code that someone else has written than write code myself, or (perhaps in manager-speak) to “leverage” third-party code. Even in the biggest software universes available, .NET or the Java platform, it is highly likely that someone outside the core development teams will have produced something I will find useful. Additionally, despite being very much a Unix developer, I frequently want my code to run on both Windows and Linux.
Note that the following experience should be taken with a large pinch of salt as I have only tried to install one extension, that extension is implicitly advertised as being of beta-quality with a version number of less than 1 and I have asked for no help on the Ocaml mailing-list. I do believe that it should be possible to install extensions without assistance.
I tried to install the ostap parser combinators extension. This library is available here. I could have easily solved my problem using GenLexer from the standard library but I thought I might as well find out how painful it is to install extensions as I will probably do it one day. ostap relies on two other libraries from the same author: Logger and TypeUtil, both of which (as far as I can remember) use camlp4 which is the Ocaml syntax extension tool.
I have a basic MinGW / MSYS setup on my Windows box so I thought I would use that to install the extensions despite the fact that it wasn’t the recommended approach. The extensions use the configure/automake stuff to generate the makefile which didn’t work so well.
During the configure stage it appears to have got confused about which slash is correct for pathnames:
checking for CamlP4 library path... C:\Program Files\Objective Caml\lib/camlp4
And then it hung while making:
make[1]: Leaving directory `/tmp/logger-0.3/regression' make[1]: Entering directory `/tmp/logger-0.3' /bin/sh: mktemp: command not found /bin/sh: $tmp_version: ambiguous redirect /bin/sh: $tmp_version: ambiguous redirect
Drat! Okay fair enough – it isn’t the recommended method. I thought I’ll try to install it on linux/x86 which must be the best supported platform and then transplant the compile commands used onto Windows. However, that didn’t work out either. It complained about missing .cma files which actually did exist within the Ocaml build tree and I needed to manually copy them across into the install directory. Then, when trying to build the sample.ml I got this:
Warning: File "sample.ml", line 12, chars 31-32: Invalid backslash escape in string Warning: File "sample.ml", line 12, chars 45-46: Invalid backslash escape in string
And then:
ocamlopt.opt -w p -I <ocaml-root>/lib/ocaml/site-lib/typeutil -I <ocaml-root>/lib/ocaml/camlp4 -I ../src -o sample.opt typeutil.cmxa camlp4.cmxa str.cmxa ostap.cmxa sample.cmx Cannot find file camlp4.cmxa $ find <ocaml-root> | egrep 'camlp4\.' <ocaml-root>/man/man1/camlp4.1 <ocaml-root>/man/man1/mkcamlp4.1 <ocaml-root>/lib/ocaml/camlp4/camlp4.cma $ find <ocaml-root> | egrep '\.cmxa$' <ocaml-root>/lib/ocaml/threads/threads.cmxa <ocaml-root>/lib/ocaml/nums.cmxa <ocaml-root>/lib/ocaml/str.cmxa <ocaml-root>/lib/ocaml/stdlib.cmxa <ocaml-root>/lib/ocaml/bigarray.cmxa <ocaml-root>/lib/ocaml/dbm.cmxa <ocaml-root>/lib/ocaml/camlp4/gramlib.cmxa <ocaml-root>/lib/ocaml/stdlib.p.cmxa <ocaml-root>/lib/ocaml/unix.cmxa <ocaml-root>/lib/ocaml/site-lib/typeutil/typeutil.cmxa <ocaml-root>/lib/ocaml/site-lib/ostap/ostap.cmxa
I did try to compile the appropriate missing files into cmxa variants manually but this stumped me too. So, what next? If I can’t getI haven’t given up on Ocaml quite yet, but I am disappointed with some of the problems I encountered. I’ll probably take a break and go back to PLT Scheme for a while, now I’ve discovered that it is more like 20 times slower than C++ than 300 (just for certain tasks of course)! Then I’ll try to install some more mature extensions and if that fails then Ocaml is not for me.