A type-safe builder uses Kotlin code to describe an object hierarchy declaratively while the type system restricts which operations are valid in each context. section 13.2.2
Build an HTML table
fun createSimpleTable() = createHTML().table { tr { td { +"cell" } } } Here, table, tr, and td are ordinary functions receiving lambdas with receivers. The table receiver exposes tr, while the tr receiver exposes td; outside those blocks, the names are unresolved. The API therefore enforces the intended HTML grammar. section 13.2.2
Receiver types define the available names in each nested block. A shared Tag superclass can collect children and render them, while a DSL marker prevents confusing access when multiple receivers are in scope.
