From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 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 346AFBBC4 for ; Wed, 4 Mar 2009 00:31:51 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnwBADdNrUnUnwckjmdsb2JhbACCHZJKAQEBAQkLCAkPBsIGhAYG X-IronPort-AV: E=Sophos;i="4.38,297,1233529200"; d="scan'208";a="25016886" Received: from relay.ptn-ipout02.plus.net ([212.159.7.36]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 04 Mar 2009 00:31:32 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj0FAAtMrUnUnw6S/2dsb2JhbACCHdULhAYG Received: from ptb-relay02.plus.net ([212.159.14.146]) by relay.ptn-ipout02.plus.net with ESMTP; 03 Mar 2009 23:31:32 +0000 Received: from [87.112.234.120] (helo=leper.local) by ptb-relay02.plus.net with esmtp (Exim) id 1Lee5D-0004Ad-MJ for caml-list@yquem.inria.fr; Tue, 03 Mar 2009 23:31:31 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] stl? Date: Tue, 3 Mar 2009 23:36:52 +0000 User-Agent: KMail/1.9.9 References: <91a2ba3e0903031340wcdc976cp52522eb35f7ccb73@mail.gmail.com> <87zlg2z19g.fsf@aryx.cs.uiuc.edu> In-Reply-To: <87zlg2z19g.fsf@aryx.cs.uiuc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903032336.53089.jon@ffconsultancy.com> X-Plusnet-Relay: af1b419546801b1de32551f08b9edd61 X-Spam: no; 0.00; stl:01 stepanov:01 unboxed:01 ocaml:01 'int:01 integers:01 ocaml:01 stl:01 arrays:01 hash:01 iterator:01 functor:01 functors:01 statically:01 functors:01 On Tuesday 03 March 2009 22:31:55 Yoann Padioleau wrote: > I don't know what are the Stepanov requirements, but C++ > can do unboxed collections like list, which OCaml can > not provide I think. a 'int list' has boxed integers in OCaml. The currently OCaml implementation never boxes ints and the boxing of other types (like float) is an artefact of the current implementation not found in other language implementations like F# and my HLVM. Moreover, this is not even a visible difference. > Also, a maybe good thing with STL is that you can write a single 'find' > or 'sort' function that will work for every kind of collections > (list, arrays, map, hash, etc) by using the > indirect iterator idiom, without the penalty of dynamic dispatch > solutions. I am not sure OCaml can do that too. OCaml can do that too. Just wrap your code in a functor and parameterize it over the module implementing the data structure (e.g. List or Array). Modules and functors are second-class statically resolved constructs in OCaml so there is no dynamic dispatch. > The question is do we really need those 2 things? Parameterizing code using functors is extremely useful but it goes far beyond the usable capabilities of C++. > I've worked a little bit with C++ using unboxed objects, that > is without introducing pointers (similar to boxing) in templates, > like list
instead of list, and passing them > as value in parameters, or returning them, > and it was far less efficient because there was lots of copy, > and you could not use then virtual method on them. So in the > end the C++ programmer I thing manually re-introduce boxing > when using STL if he wants good performance, and he can not really > rely either on the default copy/equal implementation provided > by those templates. So, yes STL makes it possible to do things, > but programmers don't want them, or only in very few cases where > one need extreme performance. The STL is extremely slow. If you want fast code in C++ then you drop to the C subset. Alex Stepanov tried and failed to implement efficient constructs in the STL. Furthermore, the memory consumption of his library is awful. OCaml's GC is far more efficient with memory whilst permitting easy sharing. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e