OCaml Rocks your Socks

Edit: Sorry about the terrible code formatting. The Editor doesn’t seem to let me put HTML where I want it. I’ll try to fix it later.

When I wrote last night’s sort-of-rant, I was thinking about OCaml. I have enough languages installed on my computer as it is, but I decided to try out OCaml for two reasons:

1) Steve Yegge likes it. If it’s good enough for Steve, then it’s good enough for me.

2) Microsoft stole it. If it’s good enough for Microsoft, it’s good enough for me.

A few minutes after beginning to toy around in the interpreter, I was afraid it was going to be just like Haskell, since their syntaxes are so similar. Haskell hurt my head. A lot. But OCaml hasn’t hurt my head; at least, not yet. In fact, I’m growing to really like OCaml. Here are a few of the reasons why:

1) It’s not impractical like Haskell or Lisp. Haskell forces you to write in a functional style, and Lisp has very few libraries for doing things like creating GUIs. OCaml has support for several paradigms, including functional, imperative, and object-oriented programming, and it has libraries for handling GUIs, creating threads, and working with files, among other things.

2) It produces concise code. This:

int factorial (int n)

if (n == 0)


return 1;




return (n * factorial (n-1));


is reduced to this:

let rec factorial n =

if(n = 0) then 1 else n * factorial (n – 1);;

3) It has a lot of Really Cool Features (RCFs), like function currying, nested functions, and pattern matching.

I’m probably going to write a quick lintroduction to the language here soon, since tutorials for it seem to be lacking. Check back soon.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: