Browse thread
[Caml-list] syntax question -- end of pattern-matching
- John Carr
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | John Carr <jfc@M...> |
| Subject: | [Caml-list] syntax question -- end of pattern-matching |
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 _ -> 42 ; "hello"
is parsed as
let f x = try x + 1 with Invalid_argument _ -> (42 ; "hello")
(and causes a type error), but if I add a second semicolon
let f x = try x + 1 with Invalid_argument _ -> 42 ; ; "hello"
is parsed as
let f x = (try x + 1 with Invalid_argument _ -> 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