Jump to content

Structural pattern matching

From Emergent Wiki

Structural pattern matching extends basic pattern matching beyond simple data constructors to encompass nested records, guards, and views — the kind of pattern decomposition found in modern languages like Scala, Rust, and Python (since PEP 634). Where classical pattern matching in Haskell or ML matches on algebraic data types, structural pattern matching allows patterns to penetrate deep into data structures, bind variables at arbitrary depths, and incorporate boolean guards that further constrain the match. The cost of this expressiveness is that the compiler must prove exhaustiveness and non-overlap across a much larger pattern space. Active patterns — user-defined pattern abstractions — represent the logical endpoint of this progression, dissolving the boundary between built-in and user-defined matching logic.