From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DB952BB81 for ; Fri, 2 Dec 2005 01:20:01 +0100 (CET) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jB20JxFx020109 for ; Fri, 2 Dec 2005 01:20:00 +0100 Received: from rosella (ppp33-4.lns1.syd6.internode.on.net [59.167.33.4]) by smtp3.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jB20Js6m062858; Fri, 2 Dec 2005 10:49:54 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] Multi-Index Container From: skaller To: Mako Tagliere Cc: caml-list@yquem.inria.fr In-Reply-To: <2670dfc80512011442g560dbfd0nabdef7c65d26d04c@mail.gmail.com> References: <2670dfc80512011442g560dbfd0nabdef7c65d26d04c@mail.gmail.com> Content-Type: text/plain Date: Fri, 02 Dec 2005 11:19:54 +1100 Message-Id: <1133482794.9266.74.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 438F932F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 ocaml:01 debugger:01 stl:01 polymorphism:01 polymorphism:01 variants:01 mylist:01 mylist:01 variants:01 recursion:01 recursion:01 elt:01 libs:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Thu, 2005-12-01 at 14:42 -0800, Mako Tagliere wrote: > Hi, > > My colleagues and I often debate the relative merits of OCaml and C++. > After I tell them how expressive, fast, and all-around nifty OCaml is > ("see! the debugger works backwards in time!"), they reply "yeah but > C++ has STL and Boost library, which make C++ every bit as expressive as > OCaml." Total Rubbish! Some people will never learn. C++ templates actually provide a bit more than ML can -- there is some real functorial polymorphism there. However it isn't properly structured, and neither is C++ polymorphism, relying on dependent name lookup as it does. C++ also doesn't have really basic things like tuples, variants and first class functions. No, don't point me at the crap in Boost -- a fine effort for C++ but it just doesn't compare with a real programming language. Just try implementing a list: in Ocaml one line: type 'a mylist = Empty | Cons of 'a * 'a mylist Just try doing THAT with variants and tuples from the Boost library. :)) Hint -- type recursion doesn't work with templates. It is possible to do it but it is VERY hard, it has to be done with open recursion, which is closed using a partial specialisation. And if you actually succeed .. hehe .. show me how to do terse pattern matching like match somelist with | Empty -> ... | Cons (elt, tail) -> .... There is one, and ONLY one good way to do all this in C++: using Felix. > When we repeated this debate recently, they challenged me to > show them an implementation of Boost's multi-index container > (http://www.boost.org/libs/multi_index/doc/index.html) in OCaml. A > bit of searching did not reveal an existing OCaml implementation. Because Ocaml doesn't generally need it. Just use modules (to enforce invariants) and multiple data structures, Ocaml boxes (shares on the heap) the data anyhow. Ocaml doesn't need multi-indexed containers in general, they're trivial. It needs the opposite -- some way of NOT sharing mutable data structures, which is the default in C++. -- John Skaller Felix, successor to C++: http://felix.sf.net