On 6 February 2014 10:58, Goswin von Brederlow <goswin-v-b@web.de> wrote:
How do you match any exception but not a successfull value?
let f5 x =
try None
with
| Empty -> ()
| val x -> x
| _ -> 1
Or does "_" only match exceptions and "val _" any value?
Interesting.
So, I would assume that the behaviour of _ would be unchanged, so it would match any exception and no value in a try and any value and no exception in a match.
The way I justify this is that "val x" or "exception x" aren't really patterns, but rather "x" is a pattern and val/exception are part of the try/match syntax. For example, "val (val x)" would presumably be a parse error. As such, "_" isn't a more general pattern than "val _", because they're different kinds of thing.
This makes me wonder if the current syntax is misleadingly uniform. Perhaps value and exception cases ought to be more clearly separated, e.g.