Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: ocaml-lib-devel@lists.sourceforge.net
Cc: caml-list@inria.fr
Subject: [Caml-list] Re: [Ocaml-lib-devel] pMap.ml
Date: Mon, 6 Oct 2003 12:54:03 +0100	[thread overview]
Message-ID: <20031006115403.GA13493@redhat.com> (raw)
In-Reply-To: <008901c38bfd$aa08b530$6f01a8c0@PWARP>

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


       reply	other threads:[~2003-10-06 11:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20031005154938.GB31811@fichte.ai.univie.ac.at>
     [not found] ` <20031006083236.GA8512@redhat.com>
     [not found]   ` <20031006090209.GA2594@fichte.ai.univie.ac.at>
     [not found]     ` <008901c38bfd$aa08b530$6f01a8c0@PWARP>
2003-10-06 11:54       ` Richard Jones [this message]
2003-10-06 12:06         ` Stefano Zacchiroli
2003-10-07 16:37           ` brogoff
2003-10-07 20:16             ` skaller
     [not found]         ` <20031006114114.GA12034@roke.freak>
     [not found]           ` <20031006125246.GA25703@cs.unibo.it>
2003-10-06 16:56             ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031006115403.GA13493@redhat.com \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    --cc=ocaml-lib-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox