<?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/07/4e344307419808f13975d9232ec23d56"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-07-19T12:00:30"
  subject="Re: [Caml-list] syntax question -- end of pattern-matching"
  prev="2002/07/2c53d122c8500845192452834a5d8d93"
  next="2002/07/85bf00d0b31dc09005c79719c1be9ec6"
  prev-in-thread="2002/07/94583a7daf36f42374916a15a02f4ce3"
  prev-thread="2002/07/16bf0e05b121ad70d4407203ffcc2060"
  next-thread="2002/07/c22d9fd21bcea5691f5678e925df1862"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] syntax question -- end of pattern-matching">
<msg 
  url="2002/07/444e872df95c217576d95f578cc60764"
  from="John Carr &lt;jfc@M...&gt;"
  author="John Carr"
  date="2002-07-18T19:27:21"
  subject="[Caml-list] syntax question -- end of pattern-matching">
<msg 
  url="2002/07/94583a7daf36f42374916a15a02f4ce3"
  from="Daniel de Rauglaudre &lt;daniel.de_rauglaudre@i...&gt;"
  author="Daniel de Rauglaudre"
  date="2002-07-19T08:33:14"
  subject="Re: [Caml-list] syntax question -- end of pattern-matching">
</msg>
<msg 
  url="2002/07/4e344307419808f13975d9232ec23d56"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-07-19T12:00:30"
  subject="Re: [Caml-list] syntax question -- end of pattern-matching">
</msg>
</msg>
</thread>

<contents>
&gt; If I write a match directly within another match, or a try ... with
&gt; expression in a sequence of expressions, it is often necessary to
&gt; use two semicolons separated by whitespace after the pattern matching.
&gt; 
&gt; For example,
&gt; 
&gt; 	let f x = try x + 1 with Invalid_argument _ -&gt; 42 ; "hello"
&gt; 
&gt; is parsed as
&gt; 
&gt; 	let f x = try x + 1 with Invalid_argument _ -&gt; (42 ; "hello")
&gt; 
&gt; (and causes a type error), but if I add a second semicolon
&gt; 
&gt; 	let f x = try x + 1 with Invalid_argument _ -&gt; 42 ; ; "hello"
&gt; 
&gt; is parsed as
&gt; 
&gt; 	let f x = (try x + 1 with Invalid_argument _ -&gt; 42;) ; "hello"

Please don't use the "; ;" form: it has never been intended to work,
it's just an unexpected consequence of some other decisions made in
the Yacc grammar.

The proper way to write what you want is

  let f x = (try x + 1 with Invalid_argument _ -&gt; 42) ; "hello"

or

  let f x = begin try x + 1 with Invalid_argument _ -&gt; 42 end; "hello"

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

