caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile@starynkevitch.net>
To: Jianzhou Zhao <jianzhou.zh@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] C++ STL bindings
Date: Mon, 10 May 2010 16:32:45 +0200	[thread overview]
Message-ID: <20100510143245.GA581@hector.lesours> (raw)
In-Reply-To: <AANLkTikDIpGMTLOWh90FFheI0Dub-gWXqO9foSOzgANs@mail.gmail.com>

On Mon, May 10, 2010 at 10:00:32AM -0400, Jianzhou Zhao wrote:


> Does anyone know if there is an OCaml binding to C++ STL libraries, or
> any other functional language with a foreign binding to such C++
> standard libraries (STL, boost)?

I believe such a beast cannot reliably exist.

The STL C++ library (and probably the Boost one also) provides a bunch
of data structure implementations in C++. All these implementation are
built on the (sad) fact that C++ manage memory (& resources)
explicitly. In other words, any data in the C++ heap was probably
allocated thru new and should probably be *explicitly* freed thru
delete.

Also the STL C++ library is heavily template based. This means some
kind of systematic code generation.

In contrast, Ocaml provide very useful generic abstract data types in
its standard library (and other common libraries...) using functors
(see the List, Array, Hashtbl, Map, Set, ... modules).

Ocaml has also a powerful garbage collector, and most functors from
its standard library take advantage of it (in a few words, in Ocaml,
allocating memory is conceptually quite cheap & efficient, and you
don't need to free it explicitly; in contrast, allocating memory
inside C++ heap is usually much slower that equivalent allocation in
Ocaml; of course the C++ memory manager has features not provided by
Ocaml's GC -real multithreading, ...-).


So the short answer to your quest is: stick to Ocaml functors (and
avoid using C++ STL in Ocaml programs).


Cheers.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


      reply	other threads:[~2010-05-10 14:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-10 14:00 Jianzhou Zhao
2010-05-10 14:32 ` Basile Starynkevitch [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100510143245.GA581@hector.lesours \
    --to=basile@starynkevitch.net \
    --cc=caml-list@inria.fr \
    --cc=jianzhou.zh@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).