Version franēaise
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2008-01-10 (17:34)
From: Christophe Raffalli <christophe.raffalli@u...>
Subject: Re: [Caml-list] Annoying behaviour of OCaml

> 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

No, I expect as fast as possible ordering to speed up Sets and Maps
as much as possible.

It is easy to write in C or in Caml (with Obj) polymorphic lexicographic comparison
if you need it. You could even start with the original compare of OCaml in compare.c if I remember well.

Now remains the question of having both a "fast_compare" (comparing size first for both string and
arrays which is not the case now) and "lex_compare" in the library ... But it does not bother me too

> compare (Array.of_list x) (Array.of_list y) = compare x y

This would become true if the hd of the list was at the rigth of the tl like in

type 'a mylist =
| Cons of 'a mylist * 'a

let rec mylist_to_list = function
  Nil -> []
| Cons(l,x) -> x::mylist_to_list l

let my_list_to_array l = Array.of_list (mylist_to_list l)

let l1 = Cons(Nil,1)
let l2 = Cons(Cons(Nil,2),1)
let b = compare (my_list_to_array l1) (my_list_to_array l2) = compare l1 l2

So this property is not really that natural.

Christophe Raffalli
Universite de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tel: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature. The public key is
stored on