<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/01/1b60c02012ca27e80ca2e81bb1bd623a"
  from="Francois Pottier &lt;francois.pottier@i...&gt;"
  author="Francois Pottier"
  date="2003-01-31T09:35:02"
  subject="[Caml-list] Lexicographic sort"
  prev="2003/01/9676deab43bb44cb174c80433348dec3"
  next="2003/01/592b98fe8dedf13711d78616753b71af"
  next-in-thread="2003/01/066d9829d769feae2e66d6d13b0c2e5f"
  prev-thread="2003/01/2da5b3338c69f028d2af213b0041adaf"
  next-thread="2003/01/2b94ee440d88d35bc171415731c354a7"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Lexicographic sort">
<msg 
  url="2003/01/1b60c02012ca27e80ca2e81bb1bd623a"
  from="Francois Pottier &lt;francois.pottier@i...&gt;"
  author="Francois Pottier"
  date="2003-01-31T09:35:02"
  subject="[Caml-list] Lexicographic sort">
<msg 
  url="2003/01/066d9829d769feae2e66d6d13b0c2e5f"
  from="Francois Pottier &lt;francois.pottier@i...&gt;"
  author="Francois Pottier"
  date="2003-01-31T09:35:52"
  subject="[Caml-list] Re: Lexicographic sort">
</msg>
<msg 
  url="2003/01/990c4428bda2b98ae593b0cb50feb144"
  from="Laurent Vibert &lt;lvibert@i...&gt;"
  author="Laurent Vibert"
  date="2003-01-31T10:34:14"
  subject="Re: [Caml-list] Lexicographic sort">
</msg>
</msg>
</thread>

<contents>

Hi,

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, _, _ -&gt;
	d

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

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

