Dictionaries
A dictionary is a hash map from string keys to values of one type, written ~{V}. The leading ~ distinguishes a dict literal from a block, since both use braces.
In a literal, keys are written as bare identifiers and values follow an =. You read a value back with ["key"].
let scores: ~{int} = ~{
alice = 10,
bob = 7,
};
let top: int? = scores["alice"]; // 10
The identifier syntax in a literal (alice = 10) is sugar — the key is the string "alice", and you index with a string (scores["alice"]). Dictionaries are plain hash maps, not an ADT; for fixed, named fields with mixed types, use a struct.
Indexing returns an option
Any key might be absent, so indexing a dict hands back an option: ~{V} yields V?, never a bare V. A present key gives the value, a missing one gives null, and you handle that null like any other option.
let scores: ~{int} = ~{ alice = 10 };
let a: int? = scores["alice"]; // 10
let b: int? = scores["zoe"]; // null
let shown = b ?? 0; // 0 — fall back when absent
Iterating
Iterating a dict binds each entry as a (key, value) pair:
for pair in ~{ x = 1, y = 2 } {
print(pair); // [x, 1], then [y, 2]
}
Dictionaries also carry built-in methods for membership and mutation, such as contains_key, insert, and remove.