Re: In Defense of Pattern Matching
Posted: Jul 6, 2006 3:59 AM
Very interesting stuff.
Ive been working on something similar myself, trying to leverage C# 3.0 features.
Unfortunately, it isnt possible to convert anonymous methods with statement blocks into expression trees, so the following sample wouldnt work with C# 3.0 as it stands.
Its a bit ugly, but heres a sample of how it might look:
Matcher match = new Matcher(
(int a, int b, int c) => Case(Foo(Bar(Baz(a,b,c),4,_))) >>
Foo foo = new Foo();
for (int i = a; i < b; i += c)
(int a) => Case(Foo(Bar(Baz(a,_,_),_,7)))) >> ()=>Foo(a),
(Baz x) => Case(Foo(Bar(x),_,_))) >> ()=>x