Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Matching when
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <pierre.weis@i...>
Subject: Re: [Caml-list] Matching when
Hi !

> I was thinking that the following should be possible :
> match e with
> | Any
> | Int x when x > 0 ->
>         .... (* here we don't use x *)
> | ....
> But the typechecker reject it because of the unbound 'x' in the "Any"
> matching.
> I don't know what kind of difficulty this modification require, but it would
> be nice if the compiler was able to resolve such cases.

I would require to analyze the set of free variables of expression
parts of match clauses to restrict the checks on variables of patterns
to this set of variables. In this case, the set of (typed) variables of
all the patterns of an ``or'' pattern should have the same intersection
with the set of free variables of the corresponding expression of the
clause, and this would solve your problem in a simple and elegant way.

This is simple and does not involve any modification of the semantics
of the language or of the pattern matching algorithm.


Pierre Weis

INRIA, Projet Cristal,,

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: