Version française
Home     About     Download     Resources     Contact us    
Browse thread
Multi-Index Container
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Multi-Index Container
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 <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net