
-----------------------------------
wtd
Mon May 02, 2005 7:26 pm

O'Caml Flexibility: Why You Should Check It Out
-----------------------------------
I'll say it up front.  O'Caml isn't the prettiest of programming languages.  It has a lot of syntactic warts.

That said, should you learn it?  Absolutely.

O'Caml is winning over more and more people because it's quite flexible.  The language itself offers all of the usual functional goodness.  Functions are first class and can be partially applied.  Types are inferred wherever possible.  It's statically typed, catching virtually all type errors at compile time.  It has pattern matching.  In addition, there are imperative features, good support for object-oriented programming, and a good module system.

Running an O'Caml program is another place where its flexibility can be seen.  O'Caml programs can be compiled to bytecode and interpreted.  They can be compiled to native machine code.  Or, for learners, there's a powerful interactive interpreter.

-----------------------------------
wtd
Tue May 03, 2005 2:34 am


-----------------------------------
Since O'Caml is often seen as a cleaner, more expressive alternative to C++ that's quicker to program in, and often produces faster code, please feel free to ask for examples implemented in both.  :)

For a starter, let's consider programs to list out all command-line arguments.

open Array
open Sys;;

Array.iter print_endline Sys.argv;;

#include 

int main(int argc, char **argv)
{
   for (int i = 0; i < argc; ++i)
   {
      std::cout 