Version française
Home     About     Download     Resources     Contact us    
Browse thread
Patterns that evaluate
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Edgar Friendly <thelema314@g...>
Subject: Re: [Caml-list] Patterns that evaluate
Jon Harrop wrote:
> On Tuesday 13 February 2007 22:04, Jacques Carette wrote:
>> I recently wrote some ocaml code which "worked", but not as I
>> intended...  The test cases I tried worked, but I should have tested
>> harder.  Apparently I was under the mistaken impression that OCaml's
>> pattern-matching was more "first class"!  So I wrote (in part):
>>
>> let buildsimp cast e f1 f2 = fun e1 -> fun e2 -> match (e1,e2) with
>>
>>                                                  | ({st = Some e}, _) -> e2
>>
>> and I expected it to work.  Only a code review by a colleague 'found'
>> this bug in my code.
>>
>> Question: would it be a difficult extension?  This seemed so "natural",
>> I just "used" the feature before it was quite there yet ;-).
> 
> F# just introduced active patterns, which does what you want AFAIK. Of course, 
> you must disambiguate that from the OCaml's current interpretation of the 
> above (binding "e").
> 
The two options I see are:
1) noting a re-binding, and automatically testing against the value of 
that previous binding
2) extra syntax (maybe || instead of | before active match constructs)

In the first case, there's backwards compatibility issues.  Wouldn't it 
be useful to have the compiler warn on such uses, to make people aware 
of rebindings performed in their code?

E.