From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 5D565BC57 for ; Mon, 10 May 2010 16:32:46 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoEDAL6150s+BBFlgmdsb2JhbACeNAEBCwsIGgMfvGyFFAQ X-IronPort-AV: E=Sophos;i="4.52,362,1270418400"; d="scan'208";a="59140722" Received: from smtp-101-monday.noc.nerim.net (HELO mallaury.nerim.net) ([62.4.17.101]) by mail1-smtp-roc.national.inria.fr with ESMTP; 10 May 2010 16:32:46 +0200 Received: from hector.lesours (ours.starynkevitch.net [213.41.244.95]) by mallaury.nerim.net (Postfix) with ESMTP id AC450A1087; Mon, 10 May 2010 16:32:44 +0200 (CEST) Received: from basile18 by hector.lesours with local (Exim 4.71) (envelope-from ) id 1OBU2H-0000Ia-It; Mon, 10 May 2010 16:32:45 +0200 Date: Mon, 10 May 2010 16:32:45 +0200 From: Basile Starynkevitch To: Jianzhou Zhao Cc: caml-list@inria.fr Subject: Re: [Caml-list] C++ STL bindings Message-ID: <20100510143245.GA581@hector.lesours> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam: no; 0.00; basile:01 basile:01 stl:01 bindings:01 ocaml:01 stl:01 ocaml:01 functors:01 hashtbl:01 functors:01 allocating:01 conceptually:01 allocating:01 ocaml's:01 cheers:01 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: basilestarynkevitchnet mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} ***