The Prototype of Echoes
Cloning magical matrices using structural sharing and record updates in Roc.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Echomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
interface PrototypeEcho
exposes [EchoMatrix, cloneAndMutate]
imports []
EchoMatrix : {
resonance : U64,
signature : Str,
stability : F64
}
baseMatrix : EchoMatrix
baseMatrix = { resonance: 100, signature: "Alpha", stability: 1.0 }
# In Roc, cloning a prototype is as simple as updating a record
cloneAndMutate : EchoMatrix, Str -> EchoMatrix
cloneAndMutate = \prototype, newSignature ->
{ prototype & signature: newSignature }
Runic Tags:
#fast-functional-wards
#roc
#prototype
#clone