<?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/990c4428bda2b98ae593b0cb50feb144"
  from="Laurent Vibert &lt;lvibert@i...&gt;"
  author="Laurent Vibert"
  date="2003-01-31T10:34:14"
  subject="Re: [Caml-list] Lexicographic sort"
  prev="2003/01/2b94ee440d88d35bc171415731c354a7"
  next="2003/01/f37d898ed760057b2a30d07937bc9aae"
  prev-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>
On Thu, 30 Jan 2003, Francois Pottier wrote:

&gt; 
&gt; Hi,
&gt; 
&gt; I just found a nice way of writing lexicographic sort in O'Caml
&gt; using Luc Maranget's recent extension of pattern syntax, which
&gt; allows a single identifier to be bound in several alternatives.
&gt; 
&gt; For instance, here is code that sorts integer triples:
&gt; 
&gt;   let compare (major1, middle1, minor1) (major2, middle2, minor2) =
&gt;     match major1 - major2, middle1 - middle2, minor1 - minor2 with
&gt;     | 0, 0, d
&gt;     | 0, d, _
&gt;     | d, _, _ -&gt;
&gt; 	d
&gt; 
&gt; Quite beautiful. Perhaps this is obvious to many, but I thought
&gt; I'd post it.
&gt; 

Warning, from the Caml manual,
http://pauillac.inria.fr/ocaml/htmlman/manual014.html
``Or'' patterns :
If both matchings succeed, it is undefined which set of bindings is 
selected

eg. if (0,0,d) and (d,_,_) succeed, you don't hnow the result...
yes in this case, it works, but in some other, it doesn't :
let f = function (_::l) | l -&gt; l
in f [1;2] 

-------------------
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>

