<?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="2002/12/a1c92ae87343785a0ac79d977ebaaeff"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-12-26T16:36:08"
  subject="Re: [Caml-list] Guards vs. conditionals"
  prev="2002/12/b223d0edf61490d3f9d2c5dcae8f3590"
  next="2002/12/ffd3fe14f523a6c74b89d10fa68e646a"
  prev-in-thread="2002/12/7ece4f35fb5ba3db3c8c56d3295a92ef"
  prev-thread="2002/12/d8e6906dcdf57f1da094ffdf57d05c60"
  next-thread="2002/12/20995c2eed42f26e0a7193d54f646852"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Guards vs. conditionals">
<msg 
  url="2002/12/955553377ddd7b841cae02e31027af85"
  from="Matt Gushee &lt;mgushee@h...&gt;"
  author="Matt Gushee"
  date="2002-12-26T07:06:59"
  subject="[Caml-list] Guards vs. conditionals">
<msg 
  url="2003/01/25dd585393832a00ec069df6b9aa3e64"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2003-01-02T09:54:24"
  subject="Re: [Caml-list] Guards vs. conditionals">
</msg>
<msg 
  url="2002/12/7ece4f35fb5ba3db3c8c56d3295a92ef"
  from="Sven Luther &lt;luther@d...&gt;"
  author="Sven Luther"
  date="2002-12-26T09:13:05"
  subject="Re: [Caml-list] Guards vs. conditionals">
<msg 
  url="2002/12/a1c92ae87343785a0ac79d977ebaaeff"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-12-26T16:36:08"
  subject="Re: [Caml-list] Guards vs. conditionals">
</msg>
</msg>
</msg>
</thread>

<contents>
[...]
&gt; &gt; So, my question is, is there any objective reason to prefer the
&gt; &gt; pattern-match version over the conditional, or vice versa? Or is it just
&gt; &gt; a matter of coding style?
&gt; 
&gt; It is just a matter of coding style. I think that the if version is
&gt; maybe easier to do prooves on or something such,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What do you mean ?

&gt; and that guard version is easier to read and maybe better when there
&gt; are more than one condition, but the compiler does not know when the
&gt; guards cover all the cases, and may output a warning when non is
&gt; needed :
&gt; 
&gt; consider :
&gt; 
&gt; let foo = function
&gt; | i when i &gt; 500 -&gt; 1
&gt; | i when i = 500 -&gt; 2
&gt; | i when i &lt; 500 -&gt; 3
&gt; 
&gt; Which will output a warning.
&gt; 
&gt; Friendly,
&gt; 
&gt; Sven Luther

The guard version has the additional good property of allowing
sequences in the clauses with no need for parens or begin end:

 | i when i &gt; 500 -&gt; print i; printe_newline ()
 | i -&gt; ...

Concerning the conjunction of guards and partial matches, the problem
is covered in large in the FAQ of the language, under the question

* Partial match with guards ?

Have a look to:

http://pauillac.inria.fr/caml/FAQ/FAQ_EXPERT-eng.html#gardes_partielles

In short, you just have to remember that the last clause does not need
a guard: use comments and the warning desapears :). For instance,

 | i (* when i &lt; 500 *) -&gt; 3

Friendly,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


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

