🐪 OCAML METAMAGIC DIFFICULTY: Apprentice Behavioral

The Command

Encapsulating arcane instructions as first-class ethereal entities for delayed execution.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Delayed Triggers
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OCAML PATTERN //
type command = unit -> unit

let invoke_fireball x y () = Printf.printf "Fireball at %d, %d!\n" x y
let invoke_heal target () = Printf.printf "Healing %s!\n" target

let ritual_queue = Queue.create ()

let () =
  Queue.push (invoke_fireball 10 20) ritual_queue;
  Queue.push (invoke_heal "Thoth") ritual_queue;
  Queue.iter (fun cmd -> cmd ()) ritual_queue

The Command pattern in OCaml is achieved simply by utilizing closures. Function parameters are bound, and the resulting thunk is queued for later incantation.

Runic Tags: #Caml Metamagic #Closures #OCaml