Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Thomas Fischbacher <tf@functionality.de>
To: Brian Hurt <bhurt@janestcapital.com>
Cc: Eric Cooper <ecc@cmu.edu>, caml-list@inria.fr
Subject: Re: [Caml-list] Annoying behaviour of OCaml
Date: Thu, 10 Jan 2008 15:47:52 +0000	[thread overview]
Message-ID: <47863E28.6080803@functionality.de> (raw)
In-Reply-To: <478639DE.6040903@janestcapital.com>

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 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

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

> Note that a *specific* ordering was ever gaurenteed- and if I wanted a 
> specific ordering, I should implement it myself.

Well... if we take e.g.:

# [|1;2;3|] < [|4;5|];;
- : bool = false

...how would you implement (non-polymorphic!) general lexicographic
order in OCaml without resorting to C?

-- 
best regards,
Thomas Fischbacher
t.fischbacher@soton.ac.uk


  reply	other threads:[~2008-01-10 15:39 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 [this message]
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=47863E28.6080803@functionality.de \
    --to=tf@functionality.de \
    --cc=bhurt@janestcapital.com \
    --cc=caml-list@inria.fr \
    --cc=ecc@cmu.edu \
    /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