Re: Suggestions

Christophe Raffalli (raffalli@cs.chalmers.se)
Wed, 13 Sep 1995 18:51:38 +0200

Date: Wed, 13 Sep 1995 18:51:38 +0200
Message-Id: <199509131651.SAA24277@waldorf.cs.chalmers.se>
From: Christophe Raffalli <raffalli@cs.chalmers.se>
To: Pierre.Weis@inria.fr
Subject: Re: Suggestions

> Why don't you use the ``when'' clauses of Caml Light 0.7?
>
> let f x =
> match read x with
> C (x1, x2) when
> (match read x1, read x2 with
> C _,C _ -> true
> | _ -> false) ->
> ...code2...
> | _ -> ...code1...
>;;

This is ok in this example, but the problem is that "when" is not a binder !

So if I want to write

let f x =
match read x with
C (x1, x2) when
(match read x1, read x2 with
C (x3,x4),C (x5,x6) -> true
| _ -> false) ->
...code2...
| _ -> ...code1...
;;

x3,x4,x5,x6 are not bound in ...code2... too bad !

With the "where match" match guard it will work and look nicer !

let f x =
match read x with
C (x1, x2) where
match read x1, read x2 with
C (x3,x4),C (x5,x6) -> ....code2....
| _ -> ...code1...
;;

The "where match" is in fact strictly more general than the when:

pat when exp ->

is equivalent to

pat where match exp with true ->

but the when is weaker because it does not bind any variable.

Christophe Raffalli.