03 / Examples
Readable by people. Predictable for models.
abstain
A function may decline to answer. Its return type says so.
// A "?" return type means: known, or abstained.
fn capital(country: Text) -> Text? {
know atlas[country] => it
else => abstain "no record for {country}"
}
match capital("Atlantis") {
known v => print(v)
abstain r => print("no answer: {r}")
}
grounds
Known values carry where they came from.
Illustrative syntax (proposal, planned for v0.3): the as clause attaches a source; the compiler tracks it through every operation.
let atlas = source "atlas.csv"
fn capital(country: Text) -> Text? {
know atlas[country] as row => row.capital grounded row
else => abstain "no record for {country}"
}
match capital("Japan") {
known v => print("{v} (from {v.grounds})")
abstain r => print(r)
}
// Tokyo (from atlas.csv:2)
Tokyo (from atlas.csv:2)
agent
Contracts for model-written code.
Illustrative syntax (proposal, planned for v1.0): tools declare what they can and cannot know, and the model's output has to satisfy the declared type.
tool order_status(id: OrderId) -> Status? {
knows "orders table, read-only"
unknown "anything about shipping carriers"
}
agent support(question: Text) -> Reply? validate strict {
use order_status
// The reply must cite a grounded Status, or abstain.
know order_status(parse_id(question)) as s => reply(s)
else => abstain "cannot answer from available tools"
}
the compile error
An unhandled abstention is rejected.
Illustrative diagnostic (proposal): the type checker treats an unhandled abstention like an unhandled error.
let c = capital("Atlantis")
print(c)
error[E012]: unhandled abstention
--> bad.dv:2:7
|
2 | print(c)
| ^ `c` is Text?, it may abstain
|
help: match on it, or write `c else "n/a"` to supply a default