Browse thread
Strange syntax error
[
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: | Jon Harrop <jon@j...> |
| Subject: | Re: [Caml-list] Strange syntax error |
On Sunday 23 January 2005 21:11, Richard Jones wrote:
> ...
> Is this a parsing bug?
I assume a "when" clause is only allowed at the end of the list of alternative
patterns. For example:
let f = function
{ keyword = keyword } -> keyword
| { keyword = keyword; cost = None } when keyword.[0] = '-' -> keyword
| _ -> failwith "whatever"
is allowed (but not what you wanted).
I guess that allowing "when" clauses on each alternative pattern would obviate
the advantages of using a decision tree to represent pattern matching and,
therefore, would make pattern matches significantly more inefficient. Hence
they don't do it.
In this case, I'd go for:
let f = function
{ keyword = keyword } when keyword.[0] = '-' -> keyword
| { cost = None } as t -> t.keyword
| _ -> failwith "whatever"
Say, this wouldn't be related to that arg-passing problem would it? ;-)
Cheers,
Jon.