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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] stl?
On Tuesday 03 March 2009 21:40:11 Raoul Duke wrote:
> hi,
>
> the caml archives show discussion around C++ polymorphism wrt STL
> (since Stepanov iirc said that C++ was the only language which
> supported what he needed to let him implement his generic programming)
> but i didn't yet see anywhere a concrete implementation or mapping
> from C++ STL to O'Caml.
>
> i'm just trying to get my head around what it might look like, and
> if/how it might be useful. (it just bugs me that somebody can claim
> that C++ is the /only/ language that could do it -- maybe the real
> quote implied "mainstream" or something. apparently Ada wasn't up to
> snuff http://www.sgi.com/tech/stl/drdobbs-interview.html)

I spent many years programming in C++ before I learned OCaml and my first 
reaction was to try to use classes for everything and to try to reinvent the 
STL in OCaml. However, the result cannot be useful because the STL simply 
represents a poor choice of trade-offs.

For example, higher-order functions like fold and map are extremely useful, 
particularly when their function argument is a closure, but that is too 
tedious to be useful in the STL whereas the ability to reuse a single "find" 
function over many different data structures is easy in the STL but useless 
in practice because you almost always know what data structure to use before 
you write the code (so you hard code List.find) and, if you don't, you just 
rename a module and use that instead (module Bindings = List ... 
Bindings.find) so there is only one code location to update. Functors give 
you the same capability in OCaml but they are rarely used precisely because 
the functionality is not very useful.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e