Sunday, April 29, 2007

Interesting papers on pattern matching

I've been reading two very interesting papers on pattern matching in the context of an object oriented language:

The Matching Objects With Patterns paper is presented in the context of Scala, and is very interesting because it discusses several approaches for OO pattern matching: object-oriented decomposition, visitors, type-tests/type-casts, typecase, case classes, and extractors. The last two approaches are Scala specific. The extractor approach (which is similar to F# active patterns) lets you create special functions that can be used to expose parts of an object to pattern matching.

The Extensible Pattern Matching via a Lightweight Language paper is presented in the context of F# and is a very nice description of the active patterns feature. This feature (which is similar to Scala extractors) allows the definition of special functions that expose parts of an object. This paper also talks about the special kinds of active patterns (with nice examples presented in each case), semantics, compilation and future work (which looks very interesting).

I think that having the option of using pattern matching on complex object models or frameworks found in .NET and the Java Platform, opens new possibilities for a more declarative and powerful code.

In future posts I hope I can post some experiments using F# active patterns and Scala extractors.

No comments: