🐪 OCAML METAMAGIC DIFFICULTY: Adept Creational

The Singleton

Ensuring only one instance of an ancient grimoire exists through lazy evaluation and reference cells.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Solitary Ward
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OCAML PATTERN //
module Grimoire : sig
  type t
  val get_instance : unit -> t
  val read : t -> string
end = struct
  type t = { secrets : string }

  let instance = lazy { secrets = "Arcane truth" }

  let get_instance () = Lazy.force instance

  let read g = g.secrets
end

The solitary ward of the Singleton is achieved through the OCaml lazy keyword, ensuring the ancient knowledge is summoned only once, yet accessible throughout the realm.

Runic Tags: #Caml Metamagic #Lazy Evaluation #OCaml