Monday, 31 December 2007

C++ vs OCaml: Ray tracer language comparison

One of our older free articles about OCaml recently resurfaced in terms of popularity, being cited from numerous French discussion forums.

This page compares and contrasts implementations of a small ray tracer in C++ and in OCaml. The resulting implementations show how easily succinct and efficient programs can be constructed in the OCaml programming language, even matching the performance of well-written C++.

For a detailed discussion of optimization in OCaml, read our book OCaml for Scientists.

Sunday, 30 December 2007

Top 10 most popular OCaml programs

We have collated a list of the world's most popular Linux software written in OCaml based upon the Debian and Ubuntu package popularity contest results and the ara database's classification of the packages:

1. FFTW

FFTW is arguably the world's fastest Fourier transform implementation and is used in many commercial applications including MATLAB as well as being freely available and prepackaged for almost all Linux distributions. The FFT routines that make up the FFTW library are C code generated by an OCaml program called genfft.

143,802 registered installs on Debian and Ubuntu.

2. Unison

Unison is a file-synchronization tool for Unix and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other.

8,786 registered installs on Debian and Ubuntu.

3. MLDonkey

MLDonkey is an open source eDonkey2000 client for peer-to-peer file sharing on Linux, Unix, Solaris, MacOSX, MorphOS and Windows.

5,010 registered installs on Debian and Ubuntu.

4. Planets

Planets is a simple interactive program for playing with simulations of planetary systems, released under the GPL. It runs on Linux and Windows.

2,429 registered installs on Debian and Ubuntu.

5. Hevea

Hevea is a high-performance LaTeX to HTML translator.

2,095 registered installs on Debian and Ubuntu.

6. FreeTennis

FreeTennis is a tennis simulator with advanced AI and real-time interactive 3D graphics.

1,837 registered installs on Debian and Ubuntu.

7. LEdit

LEdit adds line editing capabilities to programs running in shells such as bash or tcsh.

1,708 registered installs on Debian and Ubuntu.

8. Polygen

Polygen is an advanced program for generating spontaneous sentences according to a grammar definition, following custom syntactical and lexical rules.

1,594 registered installs on Debian and Ubuntu.

9. MTASC

MTASC is the world's first open source ActionScript 2 compiler.

1,030 registered installs on Debian and Ubuntu.

10. ADVI

ADVI is a viewer and presenter for DVI files that recognizes visual effects designed for giving rich presentations from a laptop.

983 registered installs on Debian and Ubuntu.

Friday, 28 December 2007

Parser combinators

The OCaml Journal just published an article explaining how concepts from functional programming can be used to construct powerful and expressive parsers:

"Certain applications are extremely well suited to functional programming and parsing is one of them. Specifically, the ability to write functional combinators that allow parsers for everything from integers up to symbolic expressions to be composed is more general and provides more opportunity for code reuse than the use of conventional parser generators such as ocamllex and ocamlyacc. This article explains how parser combinators may be designed and implemented in OCaml, using the standard example of a calculator..."

To read this article and more, subscribe to The OCaml Journal today!

OpenGL 2 for OCaml

Following our use of the GLCaml bindings to OpenGL 2 for OCaml, Elliott Oti has announced his intention to work on GLCaml more over the next month.

Elliott is one of the more practically minded contributors to the OCaml community, with a wealth of interesting examples on his site. Hopefully we can work together to get a suite of OpenGL 2 demos out there for others to learn from.

Monday, 24 December 2007

JIT compilation from OCaml using LLVM

Gordon Henriksen just took the next step in using the Low Level Virtual Machine (LLVM) project from OCaml by extending the bindings to support JIT compilation. In a post to the LLVM developers mailing list, Gordon explains how to JIT compile a simple Hello World program from OCaml using LLVM. Note that OCaml is one of the only languages to have first class bindings to LLVM bundled as part of the core LLVM distribution.

This is a really exciting development because it now makes compiler writing in OCaml much more accessible than ever before. The next milestone will be the first successful integration of an existing garbage collector with code generated by LLVM. Gordon is already working on garbage collection, several other people are working on compiler front-ends written in OCaml and dozens more people have expressed a keen interest in this project.

Thursday, 20 December 2007

Measuring memory usage in OCaml

Dimitry Grebeniuk has kindly released his objsize library. This simple C library allows you to compute the size in bytes and depth of any OCaml value.

The ability to compute the memory requirements of individual values in OCaml programs is a step towards full memory profiling and can be extremely useful in a variety of circumstances. Most notable, perhaps, is the utility of memory profiling when hunting down memory leaks, e.g. caused by unbounded memoization. This library should be in the arsenal of any self-respecting OCaml programmer.


Friday, 14 December 2007

Festive fun wth OpenGL and GTK+



The OCaml Journal just published an article that walks through the construction of a GTK application with an embedded OpenGL renderer:

"This article marries the ability to render high-quality graphics in real-time using OpenGL with the ability to build GUI applications using GTK+. Specifically, a small program is developed that builds upon functionality encountered in previous articles to render a decorated christmas tree with snow in real time..."

To read this article and more, subscribe to The OCaml Journal today!