Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Language Cookbook

This chapter collects practical, copy-paste-ready recipes for each supported language. Each example shows the builder calls and the rendered output. For the full API of each spec type, see Building Functions & Fields, Building Types & Enums, and Files & Projects.

Languages

  • TypeScript – class with imports, interface with generics, type alias, enum, abstract class
  • Rust – struct with impl, enum with variants, newtype, trait, type alias
  • Go – struct with tags, newtype, interface, generic function
  • Python – function with type hints, type alias, class with bases, dataclass, enum
  • Java – class with annotations, interface, enum, abstract class
  • Kotlin – data class, enum, interface, suspend function
  • Swift – struct with protocol conformance, enum, enum with associated values, protocol
  • C++ – class with template, using alias, enum class, virtual method, namespace wrapping
  • C – typedef, struct with fields, function declaration, enum
  • Scala – case class, trait with type parameter, enum, bounded type parameter, newtype
  • Haskell – data record with deriving, type class, function with split signature, newtype, type alias
  • OCaml – record type, function with curried params, module block, type alias, pattern match

Cross-language comparison

The same logical concept – a simple data type with two fields – rendered across four languages from the same builder structure:

LanguageOutput
TypeScriptexport class Point { x: number; y: number; }
Rustpub struct Point { pub x: f64, pub y: f64, } + separate impl block
Gotype Point struct { X float64; Y float64 }
Pythonclass Point: x: float; y: float
Scalacase class Point(x: Double, y: Double)
Haskelldata Point = Point { pointX :: Double, pointY :: Double }
OCamltype point = { x : float; y : float }

The language’s CodeLang trait controls every syntax detail: keywords, delimiters, field ordering, visibility rendering, and whether methods live inside the type body or in a separate impl block. You build the spec once and the language passed to render() does the rest.