caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jean-Christophe Filliâtre" <Jean-Christophe.Filliatre@lri.fr>
To: Berke Durak <berke.durak@exalead.com>
Cc: Caml-list List <caml-list@inria.fr>
Subject: Re: [Caml-list] Announce: xsetxmap, unfunctorized, Sexp-lib aware versions of Set and Map
Date: Mon, 21 Apr 2008 12:59:43 +0200	[thread overview]
Message-ID: <480C739F.5080104@lri.fr> (raw)
In-Reply-To: <480C60DF.9010000@exalead.com>

Berke Durak wrote:
> I decided to share my modification of the standard Set and Map modules.
> 
> Basically, I took Set and Map, unfunctorized them, passing the comparison
> function as an optional argument with Pervasives.compare as the default,

Since your library is allowing the user to pass the comparison function
to any function which requires it

  type 'elt cp = 'elt -> 'elt -> int
  val add: ?cp:'elt cp -> 'elt -> 'elt t -> 'elt t
  val mem: ?cp:'elt cp -> 'elt -> 'elt t -> bool
  ...

you should really add a *huge* warning in the documentation saying that
it is unsound to insert an element with a comparison function and then
to search for it using another one.

This is precisely where the functor approach is increasing your program
correctness, with a static binding of a single comparison function into
the code of all operations.

Even without functors, you can provide a safer approach where the
comparison function is given when creating the data structure (a la Caml
light), and stored inside. This can be an optional argument of create
for instance, so that you keep your idea of a default comparison function:

	val create: ?cp:('elt -> 'elt -> int) -> unit -> 'elt t

(Note that I agree with you that it is sometimes annoying that Set and
Map do not provide polymorphic versions using Pervasives.compare, as
Hashtbl does with the polymorphic hash funtion. I'm only concerned with
the potential risk with your solution...)

-- 
Jean-Christophe


  reply	other threads:[~2008-04-21 10:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-21  9:39 Berke Durak
2008-04-21 10:59 ` Jean-Christophe Filliâtre [this message]
2008-04-21 11:19   ` [Caml-list] " Berke Durak
2008-04-23 12:35     ` Jon Harrop
2008-04-23 13:25       ` Brian Hurt
2008-04-23 13:56         ` [Caml-list] Announce: xsetxmap, unfunctorized, Sexp-lib awareversions " David Allsopp
2008-04-23 14:22           ` Berke Durak
2008-04-26 14:44           ` Alexandre Pilkiewicz
2008-04-23 13:41       ` [Caml-list] Announce: xsetxmap, unfunctorized, Sexp-lib aware versions " Berke Durak

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=480C739F.5080104@lri.fr \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=berke.durak@exalead.com \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).