From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA07228; Mon, 6 Oct 2003 13:54:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA19182 for ; Mon, 6 Oct 2003 13:54:37 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h96Bsa118577 for ; Mon, 6 Oct 2003 13:54:36 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 1A6TwB-0003XP-00; Mon, 06 Oct 2003 12:54:03 +0100 Date: Mon, 6 Oct 2003 12:54:03 +0100 To: ocaml-lib-devel@lists.sourceforge.net Cc: caml-list@inria.fr Subject: [Caml-list] Re: [Ocaml-lib-devel] pMap.ml Message-ID: <20031006115403.GA13493@redhat.com> References: <20031005154938.GB31811@fichte.ai.univie.ac.at> <20031006083236.GA8512@redhat.com> <20031006090209.GA2594@fichte.ai.univie.ac.at> <008901c38bfd$aa08b530$6f01a8c0@PWARP> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <008901c38bfd$aa08b530$6f01a8c0@PWARP> User-Agent: Mutt/1.5.4i From: Richard Jones X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 yikes:99 mutability:01 mutability:01 extlib:01 hashtable:01 hashtable:01 hash:01 foo:01 hash:01 foo:01 baz:01 prerr:01 endline:01 baz:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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);; Rich. -- Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj Merjis Ltd. http://www.merjis.com/ - 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 caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners