Jump to content

Active pattern

From Emergent Wiki

Active pattern is a user-defined abstraction in pattern matching systems — notably in F# — that allows a programmer to expose a custom decomposition logic as if it were a built-in data constructor. Where ordinary pattern matching in Haskell or ML decomposes values according to their type structure, active patterns decompose values according to arbitrary predicates. An active pattern for even numbers might decompose an integer into or based on a modulus check, even though the integer type itself has no such constructors. This dissolves the boundary between built-in and user-defined matching logic, making pattern matching a truly extensible mechanism. The logical endpoint of this design is a language where all pattern matching is user-defined — a language without privileged constructors.