Active patterns

I promised in Chapter 4, Basic Pattern Matching, that I would add to the subject by covering active patterns; now is a perfect time. Remember matching with guards? Guards provide a way to drill down into the matched pattern-expression function by attaching an arbitrary calculation having the bool result.

Guard mechanism adds a certain customization potential to the vanilla pattern matching, but it is kind of detached: regardless of how much data decomposition is required in order to complete the guard calculation, all this effort is discarded for both matching and non-matching possible calculation results. Wouldn't it be nice to have a fully customizable transition between the recognition and transformation phases of pattern matching? ...

Get F# 4.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.