⚙️ LEAN RUNE DIFFICULTY: Adept Structural

The Bridge

Decoupling the abstract formulation of a ward from its concrete geometric implementation.

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

class WardImplementation (I : Type) where
  drawSigil : I → String

structure Glyph where
  id : Nat

instance : WardImplementation Glyph where
  drawSigil g := s!"Drawing Glyph #{g.id}"

structure AbstractWard (I : Type) [WardImplementation I] where
  impl : I

def executeWard {I : Type} [WardImplementation I] (w : AbstractWard I) : String :=
  WardImplementation.drawSigil w.impl

end MathematicalWards

The Bridge pattern is elegantly handled in Lean 4 by parameterizing the abstract ward structure over an implementation typeclass, separating abstraction from implementation.

Runic Tags: #structural #lean4 #bridge #wards