From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 5CB5EBBC1 for ; Mon, 21 Apr 2008 12:56:41 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEANsPDEjAXQIn/2dsb2JhbACqGg X-IronPort-AV: E=Sophos;i="4.25,689,1199660400"; d="scan'208";a="11708709" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 21 Apr 2008 12:56:40 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m3LAucmJ024872 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 21 Apr 2008 12:56:40 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgAANsPDEiBrw8Eo2dsb2JhbACRWgEBAQEBAQcFCQcWmAg X-IronPort-AV: E=Sophos;i="4.25,689,1199660400"; d="scan'208";a="9835425" Received: from ext.lri.fr ([129.175.15.4]) by mail2-smtp-roc.national.inria.fr with ESMTP; 21 Apr 2008 12:56:40 +0200 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id 4B7EAA463A; Mon, 21 Apr 2008 12:56:40 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lri.fr Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1ENKie8IjUyT; Mon, 21 Apr 2008 12:56:40 +0200 (CEST) Received: from [129.175.4.117] (lri4-117 [129.175.4.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ext.lri.fr (Postfix) with ESMTP id 32166A419E; Mon, 21 Apr 2008 12:56:40 +0200 (CEST) Message-ID: <480C739F.5080104@lri.fr> Date: Mon, 21 Apr 2008 12:59:43 +0200 From: =?UTF-8?B?SmVhbi1DaHJpc3RvcGhlIEZpbGxpw6J0cmU=?= User-Agent: Thunderbird 1.5.0.14ubu (X11/20080306) MIME-Version: 1.0 To: Berke Durak Cc: Caml-list List Subject: Re: [Caml-list] Announce: xsetxmap, unfunctorized, Sexp-lib aware versions of Set and Map References: <480C60DF.9010000@exalead.com> In-Reply-To: <480C60DF.9010000@exalead.com> X-Enigmail-Version: 0.94.2.0 OpenPGP: url=http://www.lri.fr/~filliatr/mykey.asc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 480C72E6.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; filliatre:01 lri:01 berke:01 durak:01 pervasives:01 val:01 val:01 bool:01 functor:01 functors:01 pervasives:01 hashtbl:01 hash:01 polymorphic:01 polymorphic:01 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