⚙️ LEAN RUNE DIFFICULTY: Adept Structural

The Proxy

A delayed invocation matrix that postpones the full mathematical evaluation of a dangerous ward until strictly necessary.

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

class WardInvocation (W : Type) where
  invoke : W → String

structure HeavyWard where
  complexity : Nat

instance : WardInvocation HeavyWard where
  invoke w := s!"Heavy ward invoked with complexity {w.complexity}"

structure WardProxy where
  baseWard : Thunk HeavyWard

instance : WardInvocation WardProxy where
  invoke p := WardInvocation.invoke p.baseWard.get

def myProxy : WardProxy :=
  { baseWard := Thunk.mk (fun _ => { complexity := 1000 }) }

end MathematicalWards

The Proxy pattern here relies on Lean’s Thunk type to delay the expensive instantiation of a ward, only evaluating it when it is invoked.

Runic Tags: #structural #lean4 #proxy #wards