Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] syntax question -- end of pattern-matching
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [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"

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 _ -> 42) ; "hello"

or

  let f x = begin try x + 1 with Invalid_argument _ -> 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