I have no formal programming background - so my experience won’t be the case
with the majority of the people on this list.
I spent 2.5 months reading and re-reading the OCaml OReilly book… and
finally I ‘understood’ when you’re supposed to use either a semi-colon,
double semi-colon, or nothing at the end of a line of OCaml code. Once I had
that breakthrough, I could ‘think’ OCaml. Ever since then I’ve been amazed
at how quick I can write very simple programs. The problem is that I mostly
write multi-user server apps, and that isn’t so ‘quick’ to do in OCaml -
Ruby OTOH is ofcourse very quick to write almost anything you want.
Remember - OCaml is based on Lambda Calculus… which I really don’t know
that much about, just that there’s only three things in LC… a function
that accepts one argument, an argument, and the application of that single
argument to a single function… or somethign like that… SO… thinking in
OCaml is nothing and i mean nothing like thinking in C, or Java, or
Ruby, or Perl.
Here’s a snippet of code from a 2 user socket server that does polling over
the connections… (yes, I know, no comments, and should have been expanded
at ';;'s. Remember - I’m not saying I’m good at this, I just get the job
done. ;-))
START CODE
let p=(int_of_string Sys.argv.(2));;let myAddr=(Unix.inet_addr_of_string
(Sys.argv.(1)));;
let sockaddr=Unix.ADDR_INET(myAddr, p);;let sock=(Unix.socket Unix.PF_INET
Unix.SOCK_STREAM 0);;
Unix.bind sock sockaddr;;Unix.listen sock 2;;
let (s,scaller)=Unix.accept sock;;let sOut=Unix.out_channel_of_descr s;;let
sIn=Unix.in_channel_of_descr s;;
let (t,scaller)=Unix.accept sock;;let tOut=Unix.out_channel_of_descr t;;let
tIn=Unix.in_channel_of_descr t;;
output_string sOut “Connected\000”;;flush sOut;;output_string tOut
“Connected\000”;;flush tOut;;
let this=ref ([s;s],[s;s],[s;s]);;
let sH=ref (String.create 1024);;let tH=ref (String.create 1024);;
sH:=“”;;tH:=“”;;
let sF=ref 0;;let tF=ref 0;;
let rS m= (if((!tF)=0) then (tH:=input_line sIn;tF:=1;print_string
“|s|”;flush stdout));;
let rT m= (if((!sF)=0) then (sH:=input_line tIn;sF:=1;print_string
“|t|”;flush stdout));;
let wS m=if((!sF)=1) then (output_string sOut (!sH ^ “\000”);flush
sOut;sH:=“”;sF:=0;print_string “-s-”;flush stdout);;
let wT m=if((!tF)=1) then (output_string tOut (!tH ^ “\000”);flush
tOut;tH:=“”;tF:=0;print_string “-t-”;flush stdout);;
while true do
try (
print_string “.”;
flush stdout;
this:=Unix.select [s;t] [s;t] [s;t] (-.1.0);
match !this with ,,[w] → (print_endline “error”;exit 0)
[w],,_ → (if(w=s) then (rS w) else (rT w))
,[w],_ → (if(w=s) then (wS w) else (wT w))
[w],,_ → (if(w=s) then (rS w) else (rT w);if(x=s) then (wS x) else
(wT x)
[w;x],,_ → (if(w=s) then (rS w;rT x) else (rT w;rS x))
,[w;x],_ → (if(w=s) then (wS w;wT x) else (wT w;wS x))
[w],[x;y],_ → (if(w=s) then (rS w) else (rT w);if(x=s) then (wS x;wT
y) else (wT x;wS y))
[w;x],[y],_ → (if(w=s) then (rS w;rT x) else (rT w;rS x);if(y=s) then
(wS y) else (wT y))
[w;x],[y;z],_ → (if(w=s) then (rS w;rT x) else (rT w;rS x);if(y=s)
then (wS y;wT z) else (wT y;wS z))
,,_ → ()
) with End_of_file → (print_endline “exiting”;exit 0)
done;;
END CODE
OCaml native code is ~better~ than C - see the language shootout to
understand what I mean.
OCaml bytecode has all the benefits of Java - plus none of the failings
(development time is shorter by far - my OCaml skill compared to my
comparably skilled Java oriented brother).
OCaml toplevel is just like IRB, there are some quirks, but it’s great for
testing a quick snippet of code before you end up using it.
OCaml is wonderfully easy to compile to a ‘native’ exe (I had to distribute
the cygwin.dll with it) or ‘close-to-crossplatform’ bytecode (I think some
libraries didn’t exist for certain platforms, but my memory is hazy on that
point), and super easy to run in a toplevel interpreter.
The bad points - exactly the same as Ruby. Next to no corporate backing
(think Sun’s marketing pocketbook), next to no ‘real-world’ uses even though
they also have a ‘these-are-the-real-world-uses’ page just like Ruby.
There is one drawback that hurt me alot - and it might have just been me…
I was very offended by the nuby mailing list responses I recieved… that
list is not for nubies. You’ve been warned. 
That’s my simple opinion.
When people ask what languages I like most, I say Ruby first, OCaml a very
close second - and no… I really have no clue how to write C or Java… and
I really don’t ever want to learn ;-).
-Rich
···
----- Original Message -----
From: prosys@chartermi.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, August 16, 2003 8:30 PM
Subject: Rite/Ruby2.0 & Ruby vs OCaml
Hi All,
I’m new here, and I hope I don’t offend anyone by mentioning a
different programming language here on Ruby-Talk.
I have two questions that are borne of the fact that I have been
searching for a language that provides both rapid development
(via an interperter) and performance (via compilation to either
byte- or native code).
I understand that Ruby is being developed towards the realization
of a VM for byte-code execution. My question is, will the
interpreter function of Ruby remain? Will I be able to have the
best of both worlds – rapid development and performance?
I looked at the comparison of various computer programming
languages at The Great Computer Language Shootout
[http://www.bagley.org/~doug/shootout/] and was a bit
disappointed to see Ruby rated as low as it was in performance.
This is the only reason I have not yet adopted Ruby.
I did notice OCaml (Objective Caml) at the top of the list –
right up there with C. And, in my investigation, I discovered
the OCaml can be run as a script interpreter and that it can
also compile byte-code and native code! Wow – just what I’ve
been looking for. But for some strange reason, I am still drawn
to Ruby.
Could someone please offer a comparison between OCaml and Ruby?
Thank you all for your time.
Best,
Terry