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,HTML_MESSAGE autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 1DC3CBC6C for ; Thu, 10 Jan 2008 16:29:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE/IhUfAXQImh2dsb2JhbACCOTWNMQEBAQgKKZkp X-IronPort-AV: E=Sophos;i="4.24,267,1196636400"; d="scan'208,217";a="6500555" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 10 Jan 2008 16:29:36 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m0AFTZJA001831 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 10 Jan 2008 16:29:36 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE/IhUdCm3xrnWdsb2JhbACCOTWNMQEBAQELDwiZQQ X-IronPort-AV: E=Sophos;i="4.24,267,1196636400"; d="scan'208,217";a="7645927" Received: from www.janestcapital.com (HELO smtp.janestcapital.com) ([66.155.124.107]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jan 2008 16:29:35 +0100 Received: from [172.25.129.161] [38.96.172.125] by janestcapital.com with ESMTP (SMTPD-9.10) id A9DE02B4; Thu, 10 Jan 2008 10:29:34 -0500 Message-ID: <478639DE.6040903@janestcapital.com> Date: Thu, 10 Jan 2008 10:29:34 -0500 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Eric Cooper Cc: caml-list@inria.fr Subject: Re: [Caml-list] Annoying behaviour of OCaml References: <4786312A.1050003@functionality.de> <20080110152017.GA513@stratocaster.home> In-Reply-To: <20080110152017.GA513@stratocaster.home> Content-Type: multipart/alternative; boundary="------------020604070201040504020908" X-Miltered: at discorde with ID 478639DF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 arrays:01 arrays:01 10,:98 10,:98 wrote:01 wrote:01 caml-list:01 int:01 int:01 behaviour:01 consistent:02 consistent:02 unexpected:03 unexpected:03 This is a multi-part message in MIME format. --------------020604070201040504020908 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Eric Cooper wrote: >On Thu, Jan 10, 2008 at 02:52:26PM +0000, Thomas Fischbacher wrote: > > >>compare [|1;2;3|] [|4;5|];; (* ...but actially is not: this gives 1, >> supposedly because the second list is >> shorter than the first. >> *) >> >> > >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. Note that a *specific* ordering was ever gaurenteed- and if I wanted a specific ordering, I should implement it myself. It certainly wasn't ever gaurenteed that the ordering would be consistent with some other (or any other) language. Ordering arrays based on length is an obvious performance advantage- it's an O(1) comparison, independent of the length of the arrays (or the cost of comparing two elements of the arrays). Brian --------------020604070201040504020908 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Eric Cooper wrote:
On Thu, Jan 10, 2008 at 02:52:26PM +0000, Thomas Fischbacher wrote:
  
compare [|1;2;3|] [|4;5|];; (* ...but actially is not: this gives 1,
			       supposedly because the second list is
			       shorter than the first.
			    *)
    

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.  Note that a *specific* ordering was ever gaurenteed- and if I wanted a specific ordering, I should implement it myself.  It certainly wasn't ever gaurenteed that the ordering would be consistent with some other (or any other) language.

Ordering arrays based on length is an obvious performance advantage- it's an O(1) comparison, independent of the length of the arrays (or the cost of comparing two elements of the arrays).

Brian

--------------020604070201040504020908--