Archive for the ‘ocaml’ Category

GP & Linux

Thursday, November 18th, 2004

I’ve been immersed in getting a Genetic Programming implementation up and running over the last few weeks. The combination of OCaml’s pattern matching and type inferencing have really come through for me, allowing me to comfortably experiment with alterations to the foundations of the system.

In the process, I’ve read quite a few research papers. CiteSeer has proven very helpful and Google just announced Google Scholar which looks promising.

Genetic Programming is extremely computationally expensive and as a result I’ve been doing quite a bit of CPU profiling lately. OCaml unfortunately doesn’t support profiling on Windows, so I’ve been spending some quality time with Linux. I’ve been surprised by how nice the latest distributions are, particularly the “sarge” release of Debian. In fact, for the first time, I now consider Linux a credible alternative to Windows on the desktop.

Life

Wednesday, October 6th, 2004

Since becoming interested in Artificial Life & computer based simulation several months ago I’ve spent a great deal of time researching Artificial Life & simulation, and a great deal of time programming. But I realized recently that most of that programming has been building foundations to do work with, but very little coding on the actual topic that got me started! So yesterday I put together a simple implementation of Conway’s Game of Life’s_Game_of_Life . If you’ve never played around with the Game of Life, I highly recommend giving it a try. My implementation (along with full OCaml source) can be downloaded here. There’s an included binary for Windows, but it should be compilable on any system that OCaml/LablGL works on.

I had a lot of fun programming my Life implementation and it’s neat to see the complex patterns that can be generated from such simple rules. The pattern that’s loaded up when the program runs is one that I found while playing around that surprised me just how interesting the result was (the pattern is just 8 cells in a jagged line, but runs for many generations).

For a much more feature rich version of Life (for Windows) check out Life32. It’s an impressive piece of work.

Objective Caml

Tuesday, September 28th, 2004

As I mentioned previously, I’ve been spending a great deal of time with Objective Caml (OCaml) recently.

Why do I like it?
* Interactive use (like Lisp, Perl, & Python) via the bytecode interpreter (ocaml).
* Compilable to assembly language for a variety of processors (including recent support for Amd64) via the optimizing compiler (ocamlopt).
* Type Inferencing provides the type safety of a language that requires a type definition for each variable (like C#, C++, Pascal, etc.) without (usually) having to declare them manually. So you get the conciseness of languages like Python or PHP without the worries of possible type errors at runtime.
* Pattern Matching is like a case statement with nitrous and supercharger bolted on. See the tutorial below for examples of the neat things you can do with it.

What don’t I like?
* OCaml is so strict about type safety & so focused on performance that there are separate operators for integers and floating point numbers. While I understand the motivation, in practice it really does get in the way when working with numbers (although usually not for other types).
* Getting the command line tools to work correctly for complicated builds (at least under Windows) can be painful.
* There are many fewer libraries available for OCaml than for Python, Perl, or .NET. (However, there is good support for OpenGL under OCaml. Check out LablGL).

Learning OCaml, for C, C , Perl and Java programmers is a great tutorial to get started with. The most pleasant way I’ve found to use OCaml interactively is under emacs with the Tuareg mode. It does very nice syntax coloring and allows the sending of expressions from the editor to the OCaml toplevel one phrase at a time, which is great for interactive development.