<?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/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"
  prev="2002/07/f3cb1029fa67245b3da380088071af64"
  next="2002/07/c22d9fd21bcea5691f5678e925df1862"
  next-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>

If I write a match directly within another match, or a try ... with
expression in a sequence of expressions, it is often necessary to
use two semicolons separated by whitespace after the pattern matching.

For example,

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

is parsed as

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

(and causes a type error), but if I add a second semicolon

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

is parsed as

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


I am unable to figure out from the grammar why this is so.

If the section 6.7 of the manual is correct, an expression may not be
empty so two semicolons separated by whitespace should not be allowed.
Thus the second form of the definition should cause a syntax error.
If an empty expression were allowed, the second form would be parsed
like the first, with "hello" as part of the expression sequence in the
"with" clause.

Is it possible to deduce ocaml's behavior from the grammar?


    --John Carr (jfc@mit.edu)
-------------------
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>

