Implemented · v0.5.0-preview.5

Types and matching

Work with static scalar types, records, choices and exhaustive matching.

The checker supports i64, bool, text and unit alongside typed collections. A shape defines named fields. A choice defines tagged alternatives that may carry typed fields.

choose and case match variants and bind payload fields. The checked structured example exercises a tagged value carrying a shape and nested list. Generic tasks are specialized for concrete types.

native-structured

examples/native-structured/src/main.zbl · v0.5.0-preview.5 · interpreter, bytecode, native

ZBL source
shape Row:
    label: text
    values: List[i64]
choice Answer:
    Ready(row: Row)
    Missing
task square(x: i64) gives i64:
    give x * x
rows: Map[text, List[Row]] = {}
values = parallel_map("square", [3, 2, 4], 2)
rows = put(rows, "numbers", [Row("native", move_value(values))])
result = Answer.Ready(rows["numbers"][0])
choose result:
    case Missing:
        show "missing"
    case Ready(row):
        show row.label
        repeat value in row.values:
            show value
Recorded output
native
9
4
16