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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 00E17BBC1 for ; Wed, 23 Apr 2008 14:42:16 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgABADrLDkjUnw6Gb2dsb2JhbACCMI8iAQwFAgUHGJs/ X-IronPort-AV: E=Sophos;i="4.25,698,1199660400"; d="scan'208";a="25387535" Received: from pih-relay08.plus.net ([212.159.14.134]) by mail4-smtp-sop.national.inria.fr with ESMTP; 23 Apr 2008 14:42:16 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay08.plus.net with esmtp (Exim) id 1JoeIh-0002iO-OL for caml-list@yquem.inria.fr; Wed, 23 Apr 2008 13:42:15 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Announce: xsetxmap, unfunctorized, Sexp-lib aware versions of Set and Map Date: Wed, 23 Apr 2008 13:35:25 +0100 User-Agent: KMail/1.9.9 References: <480C60DF.9010000@exalead.com> <480C739F.5080104@lri.fr> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200804231335.25708.jon@ffconsultancy.com> X-Plusnet-Relay: 2aa8c2db772836c574ea3afd6901376e X-Spam: no; 0.00; berke:01 durak:01 integers:01 ocaml:01 ocaml's:01 inlined:01 refactor:01 node:01 node:01 erroneously:01 hashing:01 ocaml:01 trivial:01 inlined:01 height:98 On Monday 21 April 2008 12:19:09 Berke Durak wrote: > Yes you are right, I should have put a warning. These modules are for > peculiar cases. Actually I would say that your style is more useful than the built-in Set and Map modules because you don't have to jump through hoops defining your own "Int" module with its own "int" type and its own comparison function over ints every time you want a set of integers. I would put the comparison function in the set itself though. Your modules cover 99% of use cases with the lowest syntactic overhead possible in OCaml. However, you have inherited a couple of design flaws from OCaml's standard library: . The "height" function has been inlined which has no significant effect on performance but makes it harder to refactor the code. . If you special case Node(Empty, v, Empty) to a new Node1(v) type constructor then you can improve performance by 30% by alleviating the GC. As Jean-Christophe says, it is dangerous. However, the whole language is already dangerous in this sense because it is so easy to erroneously apply polymorphic comparison or equality to the existing sets and maps and get silent data corruption. The only solution is to fix the language itself by allowing types to override comparison, equality and hashing. Another inherent problem is the inefficiency of performing comparisons in this way in OCaml. Type specialization (e.g. using a JIT) greatly accelerates this kind of code by allowing the comparison function (which is almost always trivial) to be inlined and optimized. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e