Version française
Home     About     Download     Resources     Contact us    
Browse thread
Stdlib
[ 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] Stdlib
On Mon, 2005-10-31 at 09:41 -0500, Jonathan Bryant wrote:
> Quick (and rather random question) about the standard library.  I
> noticed that, like the STL, many of the modules are very similar and
> implement many of the same functions (iter, map, etc.).  Unlike the STL
> or the Java Standard API, these modules are each completely
> independent.  Why hasn't there been a push to do something like
> functorize these modules? 

Because the technology to do that is WAY in advance of the
current Ocaml.

What you are asking for is *polyadic* functions, aka
functorial polymorphism. For example, a fold function
that works on all data structures, that is, polymorphic
not just on the data type (such as int), 
but also the data functor (such as list).

Such a function would never work with abstracted modules,
it would require data types to be defined entirely algebraically.

All of this can be done (I worked on a system that did it),
however it is definitely non-trivial. It is well in advance
of anything Haskell can do also.

In fact, C++ DOES provide such functions: the STL is built
on this concept. .. however the mechanism is not 'type safe': 
it works only by hackery based on overloading
and dependent name lookup.

This problem is partly solved in Extlib, which provides an
equivalent concept to STL iterators. However the Extlib
solution, whilst not so general as STL, is fully safe
(since it is written in Ocaml .. :)


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net