Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] ocaml and named constants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Wolfgang Lux <lux@w...>
Subject: Re: [Caml-list] ocaml and named constants
John Max Skaller wrote

> 	Unless you use a 'when' construct .. which already
> provides what I was asking for. The case when this is most
> annoying is for 'manifest constants':
> 
> 	let c1 = 1
> 	and c2 = 2
> 	in match expr with
> 	| x when x = c1 -> ..
> 	| x when x = c2 -> ..
>

Maybe it's time to ask for a little syntax extension, viz. to allow for 
multiple when clauses in a pattern matching. (This is similar to what 
is allowed e.g. in Haskell already.) Thus the above matching could be 
rewritten as:

  match expr with
    | x when x = c1 -> ..
        when x = c2 -> ..

The syntax for pattern matchings would have to be changed as follows:

 <pattern-matching> ::= ["|"] <case> { "|" <case> }
 <case> ::= <pattern> "->" <expr>
         |  "when" <expr> "->" <expr> { "when" <expr> "->" <expr> }

And a similar change would apply to <multiple-matching>. 

Wolfgang Lux


--
Wolfgang Lux				  Phone: +49-251-83-38263
Institut fuer Wirtschaftinformatik	    FAX: +49-251-83-38259
Universitaet Muenster		      Email: wlux@uni-muenster.de
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr