From: Berke Durak <berke.durak@exalead.com>
To: Thomas Fischbacher <tf@functionality.de>
Cc: Caml-list List <caml-list@inria.fr>
Subject: Re: [Caml-list] Annoying behaviour of OCaml
Date: Thu, 10 Jan 2008 16:07:43 +0100 [thread overview]
Message-ID: <478634BF.7010805@exalead.com> (raw)
In-Reply-To: <4786312A.1050003@functionality.de>
Thomas Fischbacher a écrit :
>
> Yesterday, we were bitten quite badly by a rude surprise where OCaml
> behaved in a rather different way from what we would have expected:
Surprising. I didn't notice before that arrays are compared
hierarchically and not lexicographically.
> I think it would be a *very* good idea to provide
> compare_lexicographically in addition to compare as a pre-defined built-in,
> as this is (1) what many people want to do, (2) it cannot be implemented
> without resorting to either C or black magic, and (3) it would not change
> the behaviour of already existing code that uses "compare".
Lexicographic order is quite natural for recursive sum types such as lists.
As for arrays, I guess the intent was to accelerate cases where the
array lengths are different. Assume you are sorting a random array of
arrays of random lengths, but whose contents have large common prefixes.
You'll have to do more work to sort these with lexicographical ordering.
OTOH this reasoning would also apply to strings which are compared
lexicographically... Ocaml's ways are mysterious!
However I don't think it's worth cluttering the standard library with
compare_lexicographically as it can be easily implemented.
--
Berke DURAK
next prev parent reply other threads:[~2008-01-10 15:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-10 14:52 Thomas Fischbacher
2008-01-10 15:00 ` [Caml-list] " Jean-Christophe Filliâtre
2008-01-10 15:07 ` Berke Durak [this message]
2008-01-10 15:20 ` Eric Cooper
2008-01-10 15:29 ` Brian Hurt
2008-01-10 15:47 ` Thomas Fischbacher
2008-01-10 17:33 ` Christophe Raffalli
2008-01-10 20:07 ` Oliver Bandel
2008-01-10 21:52 ` David Thomas
2008-01-10 22:29 ` Oliver Bandel
2008-01-10 22:55 ` David Thomas
2008-01-10 23:02 ` Oliver Bandel
2008-01-10 23:00 ` Oliver Bandel
2008-01-10 15:32 ` Thomas Fischbacher
2008-01-10 19:49 ` Oliver Bandel
2008-01-10 19:48 ` Oliver Bandel
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=478634BF.7010805@exalead.com \
--to=berke.durak@exalead.com \
--cc=caml-list@inria.fr \
--cc=tf@functionality.de \
/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