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
[Caml-list] Lexicographic sort
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Francois Pottier <francois.pottier@i...>
Subject: [Caml-list] Lexicographic sort


I just found a nice way of writing lexicographic sort in O'Caml
using Luc Maranget's recent extension of pattern syntax, which
allows a single identifier to be bound in several alternatives.

For instance, here is code that sorts integer triples:

  let compare (major1, middle1, minor1) (major2, middle2, minor2) =
    match major1 - major2, middle1 - middle2, minor1 - minor2 with
    | 0, 0, d
    | 0, d, _
    | d, _, _ ->

Quite beautiful. Perhaps this is obvious to many, but I thought
I'd post it.

François Pottier
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: