Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [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: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] Matching when
Luc Maranget wrote:

>>What you are asking is ``pattern when expression'' to be a pattern.
>>Then your example would be parsed as
>>
>>That is your example is to to be parsed as
>> Any              <-- pattern   | 
>>|                               | Pattern (or pat)
>> Int x when x > 0 <-- pattern   |
>>->
>>  ...             <-- right hand side
>>
>>
>>Modifications are really important because this would make patterns and
>>expression mutually recursive, which they are not at the moment.
>>
The follwing code works in Felix [it prints "YES"]

#include <std.flx>

match (2,1) with
| ( (?x when x>=1), (?y when y >=1)) when x >=2 => { print "YES"; endl; }
| _ => { print "NO"; endl; }
endmatch;

wherein 'when' expressions are part of patterns, and as you can see,
can be nested within a pattern -- making the grammar for patterns
and expressions mutually recursive.

I'm curious as to what problems you perceive with
the mutual recursion.

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners