Skip to content
Kavachकवच

Writing Types

Also known as: type annotation type inference type hints signature

● Intermediate3 minSpec 2.10

Types are written where people read them: parameters, results and record fields. Everywhere else they are worked out.

Local variablesworked out
Lambda parameters and resultsworked out
Function parameterswritten
A function's resultwritten
Record fieldswritten
fn double(x) -> Int {
    x * 2
}

fn main() {
    print(double(4))
}

The compiler refused the program:

kavach run untyped-param.kav

error: write the type of `x`: parameters always have a type
untyped-param.kav: Kavach code, then what running it prints

A signature is what people, and AI tools, read to know a function. So it is always spelled out, even for a private function; inside the body, the compiler works everything out.