Skip to content

Predicate Dispatch

A guarded method-selection mechanism that tests arguments for applicability and, in its formal form, orders applicable implementations by predicate implication.

Version
v1 · 2026-10-03 · History
Domain-specific #
13512
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomain
Programming Languages → Computer Science & Software Engineering
Aliases
Predicate dispatching

Core Idea

Predicate dispatch selects an implementation of a generic operation using guards on the actual arguments of a call. In the original formal model, a guard that logically implies another is more specific and can override it. This extends receiver-type and multiple-type dispatch to conditions involving values, state and relationships between arguments. Implementations differ: JPred restricts its guards so static checks can establish coverage and resolve overlap; Raku `where` multis are related but may use declaration order rather than formal implication.[1][2][3]

How would you explain it like I'm…

The Best-Fit Helper

Imagine a job, like 'feed the pet,' and several helpers who each wear a sign saying when they should do it: one says 'any pet,' another says 'only fish.' When a fish needs feeding, both signs fit, so the fish helper — whose sign is more exact — gets the job. Picking the helper by checking the signs is predicate dispatch.

Picking by the Narrowest Rule

In programming, one command can have several different versions. Predicate dispatch picks which version to run by checking facts about what you gave it. Each version has a rule, called a guard, saying when it applies, like 'when the number is negative'. If more than one version fits, the one with the narrower rule wins, as long as its rule always implies the other one. If two rules both fit and neither is narrower, the language has to decide some other way or say it's an error.

Guard-Based Predicate Dispatch

Predicate dispatch is a way for a program to choose which implementation of an operation to run, based on conditions about the arguments in a specific call. Each candidate method has a guard, a true-or-false condition saying when it applies. Among the methods whose guards are true, a method with guard p overrides one with guard q if p logically implies q, so the more specific method wins. This generalizes dispatch on an object's class, because a class test is just one kind of condition; predicate dispatch can also test field values or relationships between arguments. Two questions are different: whether a guard is true for these arguments (checked at run time) and whether one guard implies another for every possible input (which may need reasoning ahead of time). If two guards both apply but neither implies the other, there is no single winner unless the language adds a rule or rejects the program.

 

Predicate dispatch selects an implementation of a generic operation using predicates over the arguments of a particular call. Each method carries a guard; in the formal model, a method with guard p overrides one with guard q when p logically implies q, so the most specific applicable method is chosen without a hand-written chain of tests inside the operation. Two questions must be separated: run-time applicability (does this guard hold for these actual arguments?) and the override relation (does one guard imply another for all possible arguments?), which can require static reasoning over the whole predicate language. Rich guard syntax does not make implication decidable, so implementations such as JPred restrict the predicate language and use decision procedures for the relationships they check. Receiver-class dispatch and multimethod type dispatch fit the scheme when class tests are written as predicates; predicate dispatch additionally allows selection on field values, state or relations among arguments. That expressiveness creates a coherence obligation: if two applicable guards are incomparable under implication, there is no unique most-specific method unless the language supplies a further rule or rejects the program.

Scope of Application

The mechanism is useful when cases depend on more than argument class. In Millstein's one.world discovery-service rewrite, JPred separated event handlers by state/event, null-entry and capacity guards. The reported conversion of 20 methods exposed an ambiguity/redundancy, three potential nonexhaustive cases and removed 11 unprotected casts. These are case-study findings, not universal guarantees. Guarded multi syntax in other languages may have different precedence rules.[2][3]

Clarity

In a constructed `handle(record)` lattice, guards `true`, `ready`, `highUrgency` and `ready && highUrgency` all apply to a joint-state record. The conjunction implies both single-property guards and wins under implication ordering. Remove it and the two specialized guards overlap incomparably; source-order matching is a different policy.

Manages Complexity

Guards localize the cases instead of embedding a large conditional ladder in one method. They also make extension possible where the language supports it. Overlap becomes the central risk: adding one guarded implementation can change whether calls have a unique winner.

Abstract Reasoning

First determine which guards hold for the current arguments. Then determine which of those guards outrank the others under the actual language rule. In the formal model, implication supplies that relation. Check both coverage (some guard applies) and coherence (one method wins); do not assume that any executable guard belongs to a predicate language whose implication can be decided statically.[1][2]

Knowledge Transfer

The reusable pattern is guarded alternatives plus an explicit selection order. Predicate dispatch applies it specifically to method or function invocation; generic policy rules or if-branches are not automatically the same mechanism.

Relationships to Other Abstractions

Local relationship map for Predicate DispatchParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Predicate DispatchDOMAINPrime abstraction: Selection — presupposesSelectionPRIME

Current abstraction Predicate Dispatch Domain-specific

Parents (1) — outgoing typed relations

  • Predicate Dispatch presupposes Selection Prime

    Each predicate-dispatch invocation differentially admits and chooses applicable methods under guarded selection.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Predicate Dispatch sits in a moderately populated region (60th percentile for distinctiveness): it has near-neighbors but no dense thicket of look-alikes.

Family — Type Systems & Functional Constructs (20 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Ernst, Kaplan and Chambers, original predicate-dispatch theory (1998). registry ↩a ↩b

[2] Millstein, original JPred paper (2004). registry ↩a ↩b ↩c

[3] Official Raku multi-dispatch documentation. registry ↩a ↩b