Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-03-04 (00:14)
From: Peng Zang <peng.zang@g...>
Subject: Re: [Caml-list] stl?
Hash: SHA1

On Tuesday 03 March 2009 06:36:52 pm Jon Harrop wrote:
> On Tuesday 03 March 2009 22:31:55 Yoann Padioleau wrote:
> > Also, a maybe good thing with STL is that you can write a single 'find'
> > or 'sort' function that will work for every kind of collections
> > (list, arrays, map, hash, etc) by using the
> > indirect iterator idiom, without the penalty of dynamic dispatch
> > solutions. I am not sure OCaml can do that too.
> OCaml can do that too. Just wrap your code in a functor and parameterize it
> over the module implementing the data structure (e.g. List or Array).
> Modules and functors are second-class statically resolved constructs in
> OCaml so there is no dynamic dispatch.

As usual I want to point out the alternative: objects.  Eg. you can write a 
function that takes any object with the "find" method and look for 
<whatever>.  Objects in contrast to functors are dynamically dispatched so 
they are more flexible but just a little slower (method calls are cached).  
It also lets you make calls to find without being explict.  Eg. instead of 
List.find or Array.find or Set.Make(String).find, you can just do #find.

Version: GnuPG v2.0.7 (GNU/Linux)