From: Jon Harrop <jon@ffconsultancy.com>
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 [thread overview]
Message-ID: <200804231335.25708.jon@ffconsultancy.com> (raw)
In-Reply-To: <b903a8570804210419t674b864ex6cccd04713cbb1cd@mail.gmail.com>
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
next prev parent reply other threads:[~2008-04-23 12:42 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 ` [Caml-list] " Jean-Christophe Filliâtre
2008-04-21 11:19 ` Berke Durak
2008-04-23 12:35 ` Jon Harrop [this message]
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=200804231335.25708.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.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).