Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Multi-matches & "when", also binding values in "when" clauses
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Don Syme <dsyme@m...>
Subject: [Caml-list] Multi-matches & "when", also binding values in "when" clauses

Some questions on pattern matching....

1. - Multi-matches & "when"

I've just discovered that one can write

match x with
  | C _   | D _ -> ...
  | E | F -> ...

to catch multiple patterns by single cases.  However, if you guard the
patterns with "when" clauses, you must guard all the patterns att once

match x with
  | C _   | D _ when !foo = 3 -> ...
  | E | F -> ...

Here the "when" clause covers matches against both C and D.  Is there
any good reason for this?  It seems reasonable to be able to write

match x with
  | C _  when !foo = 4 | D _ when !foo = 3 -> ...
  | E | F -> ...

Are there any plans for this?


2. - Multiple binding in patterns

It would sometimes be nice to bind variables twice in different
patterns, as in 

match x with
  | C y | D y -> ...
  | E | F -> ...

Are there any plans for this?


3. Binding values in "when" clauses

It would be very nice to be able to bind things in the "when" clauses
and have them visible on the r.h.s.

match x with
  | C y  in 
      let z = y + 4 in 
      when !foo = z -> f z
  | D _ -> ...


Are there any plans in the work for these sorts of extensions?
Cheers,
Don

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr