Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Alternative Bytecodes for OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-08-25 (15:52)
From: John Goerzen <jgoerzen@c...>
Subject: Re: [Caml-list] Alternative Bytecodes for OCaml
On Wednesday 25 August 2004 10:22 am, Jason Smith wrote:
> > > I come to OCaml from a Python background, and one of the most
> > > interesting bits of technology for Python is Jython[1].
> >
> > Curious though why you'd want to... interfacing to C
> > I can understand. But why bother with the JVM or Java?
> Some possible reasons that suggest themselves:
> 1. You don't need to implement your own runtime environment, no more
> fussing around with garbage collection etc..
> 2. You now can run python on every platform that supports a Java
> Virtual Machine

Yes, this is a key benefit, and would apply to both Python and OCaml.

Let's say you've got an Python program and you'd like to make it easily 
runnable for as many people as possible.  You know that most of them 
have a JVM available.  So you could just distribute a .JAR file and 
poof -- instant app.  Runs on OS X, Windows, Linux, BSD, etc.

Now, s/Python/OCaml/ and perhaps s/JVM/.NET/.  You get the idea.

For OCaml developers, that means no compiling necessary for users.  No 
new environment installation.  An app can be, on Windows, 
double-click-and-run just like any other.

> 3. More so with .NET then the JVM, because .NET specifically touts
> this as a feature, but now u've got a standard type model from which
> you can interface with any other language that compiles to it.

And that is, in my mind, the key benefit.  I am just learning 
about .NET, so let's talk about Java first.

Java's type system is less rich than Python, but it is very strict and 
defined.  There are a few basic types (ints, arrays, etc.) that map 
directly into Python with no problem.  A few of the other types 
(Strings, etc.) map into Python with a little glue from Jython.  
Everything else is a class, which maps into Python with no problem at 
all.  Since every class method carries type information with it, Jython 
knows what is supposed to go in and what is supposed to come out.  In 
many cases, the whole process is completely transparent to the Python 
programmer as I demonstrated with my earlier message on the topic.

That means that, by running my Python code in Jython, I instantly get 
access to all the libraries available for Java, in addition to all the 
pure-Python libraries already out there for Python (most of them fall 
under that category).  I get all the features I like from Python, and 
can mix and match Java calls in with my code seamlessly.  I can access 
JDBC, Swing, Soap, Enhydra, whatever.  And I can still use my normal 
Python ftplib, os, sys, etc.

The best part is: NO GLUE.  That's the nasty part of interfacing to C.  
Output parameters, pointers, garbage collection, etc.  It's a lot of 
work.  There is no work to do that with Java.

Say I want to be able to create a .ZIP file from my OCaml program.  I 
could: 1) write a deflate algorithm and storage algorithm in OCaml; 2) 
develop an interface to some C library that does this (possibly taking 
almost as much time due to pointers, memory, and stuff); or 3) open and go to work.

(One interesting side-effect: Java enforces private methods at the 
compiler, not the bytecode, level.  Jython programs can actually access 
private Java class methods.)

And you're right, with .NET this benefit grows even more.  I can access 
not just Java stuff there, but also C#, some C++, Python, Perl, 
whatever else.  It's a lot to draw on, and no glue.

-- John

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: