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

Type System

WCL has a rich static type system used in schema definitions, macro parameter declarations, table column declarations, and type expressions.

Primitive Types

TypeKeywordDescriptionExample literals
StringstringUTF-8 text, supports interpolation and heredocs"hello", "port: ${p}"
Integerint64-bit signed integer (decimal, hex, octal, binary)42, 0xFF, 0o77, 0b1010
Floatfloat64-bit IEEE 754 double3.14, 1.0e-3
Booleanbooltrue or falsetrue, false
NullnullAbsence of a valuenull
IdentifieridentifierAn identifier literal (may contain hyphens)#svc-api, #my-resource

Composite Types

TypeSyntaxDescriptionExample
Listlist(T)Ordered sequence of values of type T[1, 2, 3]
Mapmap(K, V)Key-value pairs; keys are type K, values type V{ a: 1, b: 2 }
Setset(T)Unordered collection of unique values of type T[1, 2, 3]

Special Types

TypeSyntaxDescription
AnyanyAccepts a value of any type; opts out of type checking
Unionunion(T1, T2, ...)A value that may be any one of the listed types
Refref("SchemaName")A reference to a block conforming to the named schema
FunctionFirst-class lambda values; not directly nameable in type expressions

Type Expressions

Type expressions appear in schema fields, macro parameters, and table column declarations:

schema "Config" {
  port    : int
  host    : string
  tags    : list(string)
  meta    : map(string, any)
  env     : union(string, null)
  service : ref("ServiceSchema")
}
macro connect(host: string, port: int = 5432) {
  host = host
  port = port
}
table routes {
  path:    string
  method:  string
  active:  bool
  | "/api" | "GET" | true |
}

Type Coercion

WCL does not implicitly coerce between types. Type mismatches produce an error at evaluation time (E050) or schema validation time (E071). Explicit conversions are performed via built-in functions.

Exceptions:

  • Integer literals are accepted where float is expected (widening is safe).
  • null is accepted for any union(T, null) type.
  • any accepts all values without checking.

Serde Type Mapping

When serializing to JSON, YAML, or TOML, WCL types map as follows:

WCL TypeJSONYAMLTOML
stringstringstringstring
intnumber (integer)intinteger
floatnumber (float)floatfloat
boolbooleanboolboolean
nullnullnullnot representable (omitted)
identifierstring (bare name)stringstring
list(T)arraysequencearray
map(K, V)objectmappingtable
set(T)array (deduplicated)sequencearray
ref(...)resolved valueresolved valueresolved value
anynative JSON valuenativenative

Block structure is serialized as nested objects keyed by block type, then by block ID (if present).