Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Oliver Bandel <oliver@first.in-berlin.de>
To: Thomas Fischbacher <tf@functionality.de>
Cc: Brian Hurt <bhurt@janestcapital.com>, Eric Cooper <ecc@cmu.edu>,
	caml-list@inria.fr
Subject: Re: [Caml-list] Annoying behaviour of OCaml
Date: Thu, 10 Jan 2008 21:07:37 +0100	[thread overview]
Message-ID: <1199995657.47867b0972262@webmail.in-berlin.de> (raw)
In-Reply-To: <47863E28.6080803@functionality.de>

Zitat von Thomas Fischbacher <tf@functionality.de>:

> Brian Hurt wrote:
>
> >>This is indeed unexpected behavior:
> >>    # compare "123" "45";;
> >>    - : int = -1
> >>    # compare [1;2;3] [4;5];;
> >>    - : int = -1
> >>    # compare [|1;2;3|] [|4;5|];;
> >>    - : int = 1
> >>
> > It it?  I mean, all I ever read into compare was that it returned a
> > *consistent* ordering- for example, if a < b and b < c, then a < c.
>
> Well, yes, this is what the manual says and guarantees. However,
> everybody

Can you prove "everybody"?

Even if this would be the case, not what we expect
is of importance, but what the documentation says.
If there's a difference between documentation and bahaviour,
then there is a bug (in the documentation, or in the
implementation, or both).


> does expect lexicographical ordering here. In particular,
> it would be natural to have
>
> compare (Array.of_list x) (Array.of_list y) = compare x y

Well, this is one way one could expect it.
But there might be reasons not to do so.
This is mixig two paradigms, and so this might be
used differently.
The same is when using strings: OCaml's strings aren't functional.
You can change them in-place.
This is not following purely functional style, but that's not what
OCaml is prtends to provide.

I normally write my comparison functions by myself, to extract the
elements of a datastructure that should be comapred, but then
use comapre on it (even if other functions might be faster).
If I would compare more complex data structures, I would look into the
documentation. I also was surprised on that language-comparison, but now
slightly remember, this was mentioned on this list before.

Look here,

  compare [|1;2;3;5|] [|1;2;3;4|];;
- : int = 1
# compare [|1;2;3;4|] [|1;2;3;5|];;
- : int = -1
#


Nice. If the size is equal, it compares "as expected". :-)
Isn't that enough? ;-)
 Now it's clear, how to write your own function ;-)


>
> As this does not hold (see above), this is an unexpected pitfall.

That's your opinion.
There might be other opinions on it.

I would say, it's a design-decision.
And apparantly different then you would do it.

Ciao,
   Oliver


  parent reply	other threads:[~2008-01-10 20: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
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 [this message]
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=1199995657.47867b0972262@webmail.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=bhurt@janestcapital.com \
    --cc=caml-list@inria.fr \
    --cc=ecc@cmu.edu \
    --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