Multiple Continuations in Pattern Matching
Wed 25 Jun 2025 11:04 CEST
Usually, method lookup results in a single body to execute. This is analogous to the way pattern matching usually tries patterns in order, selecting just one continuation to execute.
What if, instead, we allowed all matching patterns from a bunch of alternatives to execute? (Or, in object-oriented terms: executed all methods potentially matching a given method call.)
Pattern alternatives do not become a kind of superposition, because there’s no notion of mutual exclusion; instead, they become a way of creating multiple concurrent branches of execution, somehow. (Not to say there’s any particular kind of interleaving or parallel execution of these branches that makes any sense! One could well limit consideration to sequential execution of each matching method, to start with.)
Can we recover true alternatives from this kind of every-match construct (it needs a name!)? One approach is to follow the idea from Alex’s, Mahdi’s and my PEG paper,1 treating alternation (/
) as a kind of parallel match construct and using negative lookahead to cause a later branch to fail if some earlier branch succeeds.
-
T. Garnock-Jones, M. Eslamimehr, and A. Warth, “Recognising and Generating Terms using Derivatives of Parsing Expression Grammars,” Jan. 2018. https://arxiv.org/abs/1801.10490 ↩