The Algebra of Patterns (Extended Version)

21 matt_d 1 5/3/2025, 4:40:25 AM arxiv.org ↗

Comments (1)

082349872349872 · 10h ago
I prefer a slightly different algebra of patterns, which works nicely[0] as long as sets of clauses are simplicial[1], which is to say that if any two clauses have patterns that properly intersect, the intersection also occurs as a pattern in the set of clauses: clauses match if their pattern, and no more precise[2] patterns, do.

    isWeekend : Day → String
    isWeekend(x)            := show(x) ++ " is not on the weekend"
    isWeekend(x & (Sa||Su)) := show(x) ++ " is on the weekend"
In exchange for that complication on the structure of well-formed sets of clauses, we get the following simplifications: (a) default need not be special, but is expressed by _[3], and (b) the programmer need only use positive patterns[4].

[0] as with Dijkstra's def'ns of if..fi and do..od it's possible to extend the order-independence/commutativity to non-simplicial sets of clauses without losing runtime determinativeness but at the cost of introducing arbitrariness.

[1] this is not quite accurate to the geometric use; does anyone have a better adjective?

[2] pedantically speaking, a pattern P is more specific than a pattern Q iff P is congruent to P & Q.

[3] as all clauses, not just default, exclude more specific matches

[4] negative patterns might still be useful for codegen, but they needn't be part of the developer experience. I still need to look at https://lirias.kuleuven.be/retrieve/262314/ to see how it relates to all this...