<?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/12/035f1d364ebb8d8bd82cfe75d186759a"
  from="sebastien FURIC &lt;sebastien.furic@t...&gt;"
  author="sebastien FURIC"
  date="2003-12-01T15:43:11"
  subject="[Caml-list] Question"
  prev="2003/12/9667851ffcae56aeacb848c4e966dac2"
  next="2003/12/e78561a3930717ed85eecf809e6dfd38"
  next-in-thread="2003/12/e78561a3930717ed85eecf809e6dfd38"
  prev-thread="2003/12/cf645abf5fbb4bfeb95e8a52ae1ca918"
  next-thread="2003/12/50bb73b39cc484fbbec77b6fee08aa8d"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Question">
<msg 
  url="2003/12/035f1d364ebb8d8bd82cfe75d186759a"
  from="sebastien FURIC &lt;sebastien.furic@t...&gt;"
  author="sebastien FURIC"
  date="2003-12-01T15:43:11"
  subject="[Caml-list] Question">
<msg 
  url="2003/12/e78561a3930717ed85eecf809e6dfd38"
  from="Remi Vanicat &lt;vanicat@l...&gt;"
  author="Remi Vanicat"
  date="2003-12-01T17:48:10"
  subject="Re: [Caml-list] Question">
<msg 
  url="2003/12/928ebdb82757524a715d3934786a2a64"
  from="sebastien FURIC &lt;sebastien.furic@t...&gt;"
  author="sebastien FURIC"
  date="2003-12-01T18:06:41"
  subject="Re: [Caml-list] Question">
</msg>
</msg>
<msg 
  url="2003/12/c9c38da4d98cb927dc5e77c8fe1605c9"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-12-03T14:01:41"
  subject="Re: [Caml-list] Question">
</msg>
<msg 
  url="2003/12/3f8a533bf7e11400eeb0d02ff50c1716"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2003-12-10T10:28:02"
  subject="Re: [Caml-list] Question">
<msg 
  url="2003/12/1e676f8fcefbaa708f890932f7547f19"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-12-10T16:54:10"
  subject="Re: [Caml-list] Question">
<msg 
  url="2003/12/562803867fd4a377b41a8e3a465f43b7"
  from="Luc Maranget &lt;luc.maranget@i...&gt;"
  author="Luc Maranget"
  date="2003-12-11T09:52:48"
  subject="Re: [Caml-list] Question">
<msg 
  url="2003/12/00762880f710a47d94d59f5f9e80641e"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-12-11T15:20:30"
  subject="Re: [Caml-list] Question">
<msg 
  url="2003/12/aecf296ada293906c355ef91f393e249"
  from="Luc Maranget &lt;luc.maranget@i...&gt;"
  author="Luc Maranget"
  date="2003-12-11T16:56:07"
  subject="Re: [Caml-list] Question">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
 Hi,

 What do you think of the following code?

# type toto = Toto of int | Titi of string;;
type toto = Toto of int | Titi of string
# let test t t' = match t, t' with
  | ((Toto _ | Titi _), Toto x | Toto x, (Toto _ | Titi _)) when x = 0
-&gt; "OK"
  | _ -&gt; "KO";;
Characters 73-79:
Warning: this pattern is unused.
  | ((Toto _ | Titi _), Toto x | Toto x, (Toto _ | Titi _)) when x = 0
-&gt; "OK"
                                          ^^^^^^
val test : toto -&gt; toto -&gt; string = &lt;fun&gt;
# test (Toto 0) (Toto 1);;
- : string = "KO"

 I was expecting "when" to be right distributive over "|". I find
OCaml's behaviour not very intuitive in such a situation. The correct
code is:

# let test t t' = match t, t' with
  | (Toto _ | Titi _), Toto x when x = 0 -&gt; "OK"
  | Toto x, (Toto _ | Titi _) when x = 0 -&gt; "OK"
  | _ -&gt; "KO";;
val test : toto -&gt; toto -&gt; string = &lt;fun&gt;
# test (Toto 0) (Toto 1);;
- : string = "OK"

 Is there a good reason for this?

 Cheers,

 Sébastien.

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

