English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Inline::OCaml ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-02-15 (13:53)
From: Mitchell N Charity <mcharity@l...>
Subject: [Caml-list] Inline::OCaml ?
I hope someone is working on an Inline::OCaml for Perl.

Using Perl's Inline::CPP, one can write C++ code

   #! /usr/bin/perl
   use Inline CPP => <<'ENDOFCODE';
      class counter {
	  counter()   { n = 0; }
	  void incr() { ++n; }
	  int  get()  { return n; }
	  int n;

and use it from Perl

   my $x = new counter();
   print $x->get;

and thus from Python

   from perlmod import PerlClass
   counter = PerlClass("counter")
   x = counter()
   print x.get()
It would be nice if one could also write

   #! /usr/bin/perl
   use Inline OCaml => <<'ENDOFCODE';
      class counter2 = object
	val mutable n = 0
	method incr = n <- n+1
	method get = n

   my $y = new counter2();
   print $y->get;

Creating an Inline::OCaml is a non-trivial project, but as Inline
packages have been created for C, C++, Java, Guile, Python and other
languages, it should be a feasible one.  And it will get easier as
Inline matures from its current alpha/beta-ish state, though there
may be some opportunity cost to waiting.

It appears a "multi-lingual" programming threshold is currently being
approached.  With pyperl and Inline::Python, python and perl objects
can interoperate with increasing transparency.  With perl's Inline::C,
Inline::CPP (C++), and even Inline::Java, code in those languages can
also be incorporated.

Now would seem a good time to make the case that OCaml is a better
choice than C or C++ (or Java), for writing scripting language
extensions which need to be developed rapidly and run fast.
Currently, one speeds Perl and Python programs by using extensions
written in C, and by rewriting bottlenecks, also in C.  Having Perl /
Python packages implemented in OCaml would both expose a large user
population to the existence of OCaml, and by requiring/motivating the
installation of ocaml, increase its accessibility.  Thus increasing
the number of people who get to see, try, and ultimately use OCaml.

The market forces which constrain OCaml when people decide "What
language should my _project_ be written in?", are rather different
when they ask "What language should some compartmented speed hack be
written in?".  And few care about the language of an extension, as
long as it does what they want, and the installation is easy.

So there seems to be a possible opportunity here for OCaml to gain
exposure and expand its user base.

Just a thought,
Mitchell Charity
(back to writing a Perl/Python extension in C and C++... sigh...)

Some links:

     and, current as of 2002-Feb-13:

Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr