🌐 REASONML PACT DIFFICULTY: Adept Behavioral

Visitor in ReasonML

Traversing ASTs with external pattern matching functions.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Exploration
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// REASON PATTERN //
type element = NodeA | NodeB(string);

let visit = (el) =>
  switch (el) {
  | NodeA => "Visited A"
  | NodeB(s) => "Visited B with " ++ s
  };

The Visitor pattern is arguably the most fundamental capability of ReasonML: pattern matching over discriminated unions perfectly decouples data from operations.

Runic Tags: #reason #visitor #behavioral