⚙️ LEAN RUNE DIFFICULTY: Adept Structural

The Decorator

Dynamically attaching additional mathematical invariances to a ward without altering its core geometry.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Enchantment // Augmentation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// LEAN PATTERN //
namespace MathematicalWards

class Ward (W : Type) where
  power : W → Nat

structure CoreWard where
  basePower : Nat

instance : Ward CoreWard where
  power w := w.basePower

structure ElementalDecorator (W : Type) where
  inner : W
  bonus : Nat

instance {W : Type} [Ward W] : Ward (ElementalDecorator W) where
  power w := Ward.power w.inner + w.bonus

def decorated : ElementalDecorator CoreWard :=
  { inner := { basePower := 10 }, bonus := 5 }

#eval Ward.power decorated -- 15

end MathematicalWards

Decorators in Lean 4 wrap existing types and delegate typeclass behavior while augmenting functionality.

Runic Tags: #structural #lean4 #decorator #wards