Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 {
	public:
	  counter()   { n = 0; }
	  void incr() { ++n; }
	  int  get()  { return n; }
	private:
	  int n;
      };
   ENDOFCODE

and use it from Perl

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

and thus from Python

   from perlmod import PerlClass
   counter = PerlClass("counter")
   x = counter()
   x.incr()
   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
      end;;
   ENDOFCODE

   my $y = new counter2();
   $y->incr;
   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:

   Inline
      http://inline.perl.org/
      http://search.cpan.org/search?mode=module&query=Inline%3a%3a
     and, current as of 2002-Feb-13:
      http://search.cpan.org/doc/INGY/Inline-0.43/Inline-API.pod
      http://search.cpan.org/doc/INGY/Inline-0.43/Inline.pod
      http://search.cpan.org/doc/INGY/Inline-0.43/C/C.pod
      http://search.cpan.org/doc/INGY/Inline-0.43/C/C-Cookbook.pod
      http://search.cpan.org/doc/NEILW/Inline-Python-0.20/Python.pod
      http://search.cpan.org/doc/PATL/Inline-Java-0.31/Java.pod

   pyperl
      http://conferences.oreillynet.com/cs/os2001/view/e_sess/1437
      http://www.zope.org/Wikis/zope-perl/
-------------------
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