Saturday, April 26, 2008 1:29 AM bart

The Return of the Pattern Matcher - Sample Code Available

It's been a while since I continued my series on a functional pattern matcher in C#. I finally found some time to extract the simplified pattern matching code from the bigger project I'm working on and cook up a downloadable documented sample. Without further delay: here it is.

image

It contains most of the matching techniques outlined in this blog series:

  • NewExpression (with metadata on constructor arguments)
  • MemberInitExpression
  • ConstantExpression (the degenerated case of a classic switch)
  • ParameterExpression (the degenerated case of a type switch)
  • ListInitExpression

Obviously there are a bunch of restrictions, namely:

  • No support for nested constructs, e.g. a match on a list of persons with parameters in the Person object expressions
  • No caching of results (cf. the Fibonacci sample)
  • Optimizations

The code comes with a set of samples showing the supported matches in practice. There's more fun stuff to come but timing is still undecided, so watch out :-). Enjoy!

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under: , ,

Comments

# The Return of the Pattern Matcher - Sample Code Available

Saturday, April 26, 2008 1:34 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com