Version franēaise
Home     About     Download     Resources     Contact us    
Browse thread
Annoying behaviour of OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@j...>
Subject: Re: [Caml-list] Annoying behaviour of OCaml
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