The Composite of the Progenitor
Build fractal arcane structures using algebraic datatypes.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Conjuration // Fractal Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
datatype spell_component =
SingleRune of string
| RuneCluster of spell_component list
fun evaluate (SingleRune r) =
print ("Activating rune: " ^ r ^ "\n")
| evaluate (RuneCluster clusters) =
(print "Opening cluster...\n";
app evaluate clusters;
print "Closing cluster.\n")
val megaSpell = RuneCluster [
SingleRune "Ignis",
RuneCluster [
SingleRune "Aer",
SingleRune "Motus"
],
SingleRune "Finis"
]
val _ = evaluate megaSpell
For the ML Progenitor, the Composite pattern is not a design pattern; it is a fundamental way of life. Algebraic datatypes allow you to recursively define spell_component as either a single leaf or a branch containing a list of its own type. A simple recursive function uses pattern matching to seamlessly execute both primitive runes and sprawling rune clusters.
Runic Tags:
#datatypes
#trees
#recursion