Types & Annotations
Dynamic runtime values, strict operations, missing, and compile-time type annotations with union types.
Core Value Types
| Type | Literals / Examples | Notes |
|---|---|---|
int | 42, 0, -7 | Exact signed integer |
float | 1.5, 1e-3 | Finite IEEE-754 floating-point |
string | "hello\n" | UTF-8 immutable text |
bool | true, false | Strict boolean (no truthy ints) |
missing | missing | Explicit null / absent value |
list | [1, 2, 3] | Ordered immutable sequence |
record | {name: "dlang"} | Immutable key-value record |
Optional Static Type Annotations
Variables, function parameters, and return types accept optional type annotations validated by dlang check and the compiler frontend.
typed.dl
count: int = 0
items: list<int> = [1, 2, 3]
fn find_user(id: int) -> string | missing
if id == 1
return "Ada"
end
return missing
endStrict Operations
Dlang does not silently coerce types in
+ or ==. Use to_string(x), to_int(x), to_float(x), or to_bool(x) for explicit conversions.