Exhaustiveness and Redundancy in Pattern Matching
Find a concrete missing branch by expanding cases over a finite set of constructors and tracking which patterns remain useful.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Treat patterns as sets of values
For an optional Boolean, clauses for empty and present true leave present false uncovered. A final wildcard covers it, but one placed first renders the later cases unreachable in ordered matching. An exhaustiveness check asks whether any value reaches the end without a match. A redundancy check asks whether a particular clause can be reached after all earlier clauses have failed.
Specialize on constructors one column at a time
For a constructor pattern, restrict attention to values with that constructor and continue on its fields. A wildcard expands to matching field wildcards for every possible constructor, subject to the types. This technique works for nested patterns without listing an infinite value space. Guards that cannot be decided statically may limit the guarantee. Algebraic data types provide the finite constructor choices. Decision-tree compilation turns the analyzed clauses into tests while preserving match order.[1][2]