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] Re: [Ocaml-lib-devel]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-06 (11:54)
From: Richard Jones <rich@a...>
Subject: [Caml-list] Re: [Ocaml-lib-devel]
Nicolas Cannasse wrote:
> Markus Mottl wrote:
> > I wrote:
> > > Yikes. The good thing about the previous code was it _wasn't_ purely
> > > functional.
> > >
> > > I'll never understand this fear of mutability.
> >
> > I have no fear of mutability. It's just that there was absolutely
> > no apparent advantage of having mutability in this datastructure,
> > neither performance- nor expressiveness-wise. A reference holding this
> > datastructure outside of the library would do as well. You are not afraid
> > of dereferencing values, are you? ;-)
> Manipulating references is most of the time quite a pain, and make the code
> quite ugly.
> I understand in some cases the need of pure functional data structure (Coq
> code proof) but in the "average user" cases that target ExtLib, having a
> mutable structure is surely better. For example I often use an Hashtable
> where a Map would be better for theses two reasons :
> - no need to define a module type (this is corrected by this polymorphic
> version)
> - the hashtable is mutable ! means, easy to use.

While I'm certainly not an experienced OCaml programmer like Markus
and Nicolas, I have to come down on the Nicolas's side here.

Hashtbls are much easier to use than Maps precisely for the reasons he
has outlined. They'd be even better if the language offered syntactic
support for them (but this just reflects my Perl background), eg:

let hash = {| "foo", "bar"; "a", "b" |} in
hash.{"foo"} <- "baz";
prerr_endline hash.{"foo"};	# would print "baz"

While we're about it, Hashtbl.keys and Hashtbl.values functions would
be really useful in the standard library. They are defined simply as:

let keys = Hashtbl.fold (fun key _ xs -> key :: xs);;
let values = Hashtbl.fold (fun _ value xs -> value :: xs);;


Richard Jones.
Merjis Ltd. - all your business data are belong to you.
"One serious obstacle to the adoption of good programming languages is
the notion that everything has to be sacrificed for speed. In computer
languages as in life, speed kills." -- Mike Vanier

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: