The Visitor Apparition
Separating an algorithm from the object structure on which it operates.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Necromancy // Astral Projection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module VisitorPattern where
open import Data.String
data Element : Set where
NodeA : String → Element
NodeB : String → Element
record Visitor (R : Set) : Set where
field
visitA : String → R
visitB : String → R
accept : {R : Set} → Element → Visitor R → R
accept (NodeA s) v = Visitor.visitA v s
accept (NodeB s) v = Visitor.visitB v s
The Visitor Apparition
When inspecting a sprawling AST or physical network architecture, adding a new diagnostic spell directly to the structures poisons their purity. The Visitor Apparition separates the logic from the structure.
The Dependent Runes
By defining an accept function, elements open themselves to arbitrary Visitor logic. With dependent types, we ensure the visitor must exhaustively handle every possible element variation (NodeA, NodeB) or fail to compile.
Runic Tags:
#agda
#visitor
#astral