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
[Caml-list] two unrelated questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-02 (09:59)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] two unrelated questions
Brian Rogoff wrote:

> > It's a pity there is no such destructor for a Hashtbl.
> > [All C++ STL data structures have read iterators, which
> > amount to destructors]
> Are they really the same? I think of STL style iterators as being more
> similar to array indices, and arrays (and hashtables) are not defined
> inductively like lists, trees, and graphs, etc.

	Well, for an iterator p, there are three operations:


But they're usually combined like:


which is equivalent to getting one element of the container p denotes,
and adjusting p to denote the rest of the container.

> As I'm sure you know, there is an easy enough transformation from
> hashtables (and arrays) to lists, like the following
> let pairs_of_hashtbl ht =
>   let pl_ref = ref [] in
>   let fn a b = (pl_ref := (a,b)::(!pl_ref) in
>   (Hashtbl.iter fn ht; !pl_ref)

	Sure, but this requires building a new data structure.
Even if that is OK for traversal, it can't handle mutating

	Of course, people don't use STL algorithms as much in C++
as they might, because there is no support for nested anonymous
functions (lambdas) or currying, which are essential for localisation.
And of course Ocaml is _good_ at that :-)

John (Max) Skaller,
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper
download Interscript
To unsubscribe, mail  Archives: