Command in ReasonML
Reifying actions as variant payloads.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Evocation // Channeling
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// REASON PATTERN //
type command =
| Move(int, int)
| Attack(string);
let execute = (cmd) =>
switch (cmd) {
| Move(x, y) => Js.log2("Moving to", (x, y))
| Attack(target) => Js.log2("Attacking", target)
};
The Facebook Functional Pacts represent commands not as objects, but as algebraic data types, enabling powerful replay and undo mechanics.
Runic Tags:
#reason
#command
#behavioral