caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Multi-Index Container
@ 2005-12-01 22:42 Mako Tagliere
  2005-12-02  0:19 ` [Caml-list] " skaller
  2005-12-02  0:53 ` Jon Harrop
  0 siblings, 2 replies; 3+ messages in thread
From: Mako Tagliere @ 2005-12-01 22:42 UTC (permalink / raw)
  To: caml-list

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."  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.

Would someone in the OCaml community be willing to sketch out such an
implementation?

Thanks
Mako Tagliere


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Multi-Index Container
  2005-12-01 22:42 Multi-Index Container Mako Tagliere
@ 2005-12-02  0:19 ` skaller
  2005-12-02  0:53 ` Jon Harrop
  1 sibling, 0 replies; 3+ messages in thread
From: skaller @ 2005-12-02  0:19 UTC (permalink / raw)
  To: Mako Tagliere; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Multi-Index Container
  2005-12-01 22:42 Multi-Index Container Mako Tagliere
  2005-12-02  0:19 ` [Caml-list] " skaller
@ 2005-12-02  0:53 ` Jon Harrop
  1 sibling, 0 replies; 3+ messages in thread
From: Jon Harrop @ 2005-12-02  0:53 UTC (permalink / raw)
  To: caml-list

On Thursday 01 December 2005 22:42, Mako Tagliere wrote:
> 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."  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.
>
> Would someone in the OCaml community be willing to sketch out such an
> implementation?

In order to compare different languages meaningfully, you should try to solve 
problems by writing independent implementations in different languages.

There is no point in trying to mimic individual features, paradigms or styles 
found in other languages, as you suggest. Paul Graham's infamous "accumulator 
generator" challenge is a fine example this mistake:

  http://www.paulgraham.com/accgen.html

So you should ask your friends to try to come up with a real task with a C++ 
implementation that benefits from Boost's functionality, and then write your 
own implementation in OCaml before comparing the two.

I thought the examples from the page that you cite might have been suitable 
but the ones that I have looked at are all trivial in OCaml (and C++).

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-02  0:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-01 22:42 Multi-Index Container Mako Tagliere
2005-12-02  0:19 ` [Caml-list] " skaller
2005-12-02  0:53 ` Jon Harrop

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).