✨ ARCANUM RUNE DIFFICULTY: Adept Creational

The Singleton Monolith

Ensuring only one instance of the Archmage's state exists within the current execution hex.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Sealing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
effect state<a,e>
  fun get() : a
  ctl set(v : a) : ()

fun with-singleton(init: a, action: () -> <state<a,e>|e> b) : e b
  var current := init
  with handler
    fun get() current
    ctl set(v) { current = v; resume(()) }
  action()

pub fun main()
  with with-singleton(42)
  val mana = get()
  println("Mana pool: " ++ mana.show)
  set(mana - 10)
  println("Remaining: " ++ get().show)
Runic Tags: #koka #singleton #state-effect