🐪 OCAML METAMAGIC DIFFICULTY: Apprentice Behavioral

The Visitor

Traversing a heterogeneous menagerie of magical beasts and applying diverse effects without mutating their essence.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Conjuration // Menagerie Traversal
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OCAML PATTERN //
type beast = Dragon | Griffin | Mimic

let feed = function
  | Dragon -> "Fed molten rock."
  | Griffin -> "Fed raw meat."
  | Mimic -> "Fed a gold coin."

let pet = function
  | Dragon -> "Burned hand."
  | Griffin -> "Purrs loudly."
  | Mimic -> "Lost hand."

In functional OCaml, the Visitor pattern is inherently solved by defining operations over an Algebraic Data Type via pattern matching, keeping the data structures pure and separated from their behaviors.

Runic Tags: #Caml Metamagic #Pattern Matching #OCaml